kickstart-G

感觉自己很蠢,large数据只能交一次,忘记这回事了

A题 O(n^2)解法,用vector<set> 缓存j后面的数据,减少一重循环

 #include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<queue>
#include<cmath>
#include <set>
#include<algorithm>
#include<cstring> using namespace std;
int a[];
int main(){
//freopen("/Users/zjg/CLionProjects/ac/A-large-attempt0.in","r",stdin);
//freopen("/Users/zjg/CLionProjects/ac/A-large-attempt0.out","w",stdout);
int kase;
cin>>kase;
for(int k=;k<kase;k++){
int n;
cin>>n;
for(int i=;i<n;i++)
{
cin>>a[i];
}
vector<set<long long>> v(); for(int i=n-;i>=;i--)
{
for(int j=i+;j<n;j++)
v[i].insert(a[j]);
} long long ans=;
for(int i=;i<n;i++)
for(int j=i+;j<n;j++)
{ if(a[i]*a[j]<=&&v[j].count(a[i]*a[j]))
ans++;
else if(a[j]!=&&(a[i]/float(a[j])==a[i]/a[j])&&v[j].count(a[i]/a[j]))
ans++;
else if(a[i]!=&&(a[j]/float(a[i])==a[j]/a[i])&&v[j].count(a[j]/a[i]))
ans++;
}
cout<<"Case #"<<k+<<": "<<ans<<endl;
}
return ;
}
上一篇:教你彻底搞懂Cocos Creator Tween


下一篇:vim recording