kickstart-G
感觉自己很蠢,large数据只能交一次,忘记这回事了
A题 O(n^2)解法,用vector<set> 缓存j后面的数据,减少一重循环
1 #include <string> 2 #include <vector> 3 #include<iostream> 4 #include<cstdio> 5 #include<queue> 6 #include<cmath> 7 #include <set> 8 #include<algorithm> 9 #include<cstring> 10 11 using namespace std; 12 int a[7007]; 13 int main(){ 14 //freopen("/Users/zjg/CLionProjects/ac/A-large-attempt0.in","r",stdin); 15 //freopen("/Users/zjg/CLionProjects/ac/A-large-attempt0.out","w",stdout); 16 int kase; 17 cin>>kase; 18 for(int k=0;k<kase;k++){ 19 int n; 20 cin>>n; 21 for(int i=0;i<n;i++) 22 { 23 cin>>a[i]; 24 } 25 vector<set<long long>> v(7000); 26 27 for(int i=n-1;i>=0;i--) 28 { 29 for(int j=i+1;j<n;j++) 30 v[i].insert(a[j]); 31 } 32 33 long long ans=0; 34 for(int i=0;i<n;i++) 35 for(int j=i+1;j<n;j++) 36 { 37 38 if(a[i]*a[j]<=200000&&v[j].count(a[i]*a[j])) 39 ans++; 40 else if(a[j]!=0&&(a[i]/float(a[j])==a[i]/a[j])&&v[j].count(a[i]/a[j])) 41 ans++; 42 else if(a[i]!=0&&(a[j]/float(a[i])==a[j]/a[i])&&v[j].count(a[j]/a[i])) 43 ans++; 44 } 45 cout<<"Case #"<<k+1<<": "<<ans<<endl; 46 } 47 return 0; 48 }