标签:ace otto view accept style code title ram scanf
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1758 Accepted Submission(s): 577
思路:暴力
1 #include<bits/stdc++.h> 2 using namespace std; 3 const int N=105; 4 5 int a[N]; 6 int n; 7 set<int > s[2100],ss; 8 set<int >::iterator it,it1,it2; 9 int main(){ 10 int t; 11 cin>>t; 12 while(t--){ 13 scanf("%d",&n); 14 ss.clear(); 15 for(int i=0;i<=2100;i++) s[i].clear(); 16 for(int i=1;i<=n;i++){ 17 scanf("%d",&a[i]); 18 s[a[i]].insert(1); 19 ss.insert(a[i]); 20 } 21 for(int i=1;i<=n;i++){ 22 int x=a[i]; 23 for(int j=i+1;j<=n;j++){ 24 x=x^a[j]; 25 ss.insert(x); 26 if(!s[x].empty()){ 27 if(*s[x].begin()<(j-i+1)){ 28 int y=*s[x].begin(); 29 s[x].erase(y); 30 s[x].insert(j-i+1); 31 } 32 } 33 else 34 s[x].insert(j-i+1); 35 } 36 } 37 int q; 38 scanf("%d",&q); 39 while(q--){ 40 int m; 41 scanf("%d",&m); 42 it=ss.upper_bound(m); 43 if(it!=ss.end()){ 44 int xx=*it; 45 if(it!=ss.begin()){ 46 it--; 47 int yy=*it; 48 if(abs(yy-m)<abs(xx-m)){ 49 printf("%d\n",*(s[yy].begin())); 50 } 51 else if(abs(yy-m)>abs(xx-m)){ 52 printf("%d\n",*(s[xx].begin())); 53 } 54 else { 55 printf("%d\n",max(*(s[xx].begin()),*(s[yy].begin()))); 56 } 57 } 58 else { 59 printf("%d\n",*(s[xx].begin())); 60 } 61 } 62 else { 63 it--; 64 printf("%d\n",*(s[*it].begin())); 65 } 66 } 67 printf("\n"); 68 } 69 return 0; 70 }
标签:ace otto view accept style code title ram scanf
原文地址:http://www.cnblogs.com/hhxj/p/7610820.html