ZJNU 2356 - six scientists

"Elected three six experts, they are numbered i, j, k, satisfies i <j <k, and a [k] = a [j] -a [i]"

Therefore, when the i-th input a [i], plus the number of number of answers directly before i-1 can be constructed in the difference is a [i] to the

Then let the number of input at this time as in the above formula a [j], the i-1 to 1 as the a [i], i-1 lists possible a [k] can save up

The time complexity is O (n * n / 2)

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 int ar[2005],cha[400005];
 4 int main(){
 5     ios::sync_with_stdio(0);
 6     cin.tie(0);cout.tie(0);
 7     int n,i,j,ans=0;
 8     cin>>n;
 9     if(n<3){
10         cout<<0<<endl;
11         return 0;
12     }
13     memset(cha,0,sizeof cha);
14     cin>>ar[0]>>ar[1];
15     cha[ar[1]-ar[0]+200000]=1;
16     for(i=2;i<n;i++){
17         cin>>ar[i];
18         ans+=cha[ar[i]+200000];
19         for(j=0;j<i;j++)
20             cha[ar[i]-ar[j]+200000]++;
21     }
22     cout<<ans;
23     
24     return 0;
25 }

 

Guess you like

Origin www.cnblogs.com/stelayuri/p/12239004.html