topic
analysis
- This question is just the beginning, I used to run fast row
- No later found, called n ^ 2
- The water then had a 50
- Later, I direct 1-2 ^ 20 * n to run, found that the direct bombing
- Correct solution:
- We want to take advantage of the number 1 directly to the formation of several
- Such a find can be output directly after the
Code
1 #include<iostream> 2 #include<cmath> 3 #include<algorithm> 4 #include<cstdio> 5 #include<cstring> 6 #define N 10000000 7 #define ll long long 8 using namespace std; 9 string s; 10 int a[N]; 11 int n; 12 int h[N]; 13 ll tran(string s) 14 { 15 ll i,a,b; 16 double k,h=0; 17 a=s.length(); 18 b=a-1; 19 for (i=0;i<=a;i++) 20 { 21 if (s[i]<='9'&&s[i]>='0') 22 s[i]=s[i]-'0'; 23 else if (s[i]<='F'&&s[i]>='A') 24 s[i]=s[i]-'A'+10; 25 k=s[i]*pow(16, b); 26 h+=k; 27 b--; 28 } 29 return h; 30 } 31 bool dfs(int x,int y,int l,int r) 32 { 33 if (l==r+1) 34 { 35 for (int i=1;i<=n;i++) 36 if (h[a[i]^x]==1) return 1; 37 return 0; 38 } 39 for (int i=y+1;i<=20;i++) 40 { 41 int m=(1<<i); 42 if (dfs(x+m,i,l+1,r)) return 1; 43 } 44 return 0; 45 } 46 int main () 47 { 48 int T; 49 cin>>T; 50 while (T) 51 { 52 memset(h,0,sizeof(h)); 53 T--; 54 cin>>n; 55 for (int i=1;i<=n;i++) 56 { 57 cin>>s; 58 int t=tran(s); 59 a[i]=t; 60 h[a[i]]=1; 61 } 62 int ans=1; 63 while (1) 64 if (dfs(0,-1,1,ans)) break; 65 else ans++; 66 cout<<ans<<endl; 67 } 68 }