标签:lib iss logs 集合 程序设计 comm 异或 queue chmod
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 132768/132768 K (Java/Others)
Total Submission(s): 2505 Accepted Submission(s): 1076
1 #pragma comment(linker, "/STACK:102400000,102400000") 2 #include <bits/stdc++.h> 3 #include <cstdlib> 4 #include <cstdio> 5 #include <iostream> 6 #include <cstdlib> 7 #include <cstring> 8 #include <algorithm> 9 #include <cmath> 10 #include <cctype> 11 #include <map> 12 #include <set> 13 #include <queue> 14 #include <bitset> 15 #include <string> 16 #include <complex> 17 #define LL long long 18 #define mod 1000000007 19 using namespace std; 20 int t; 21 int n,m; 22 struct Tire 23 { 24 int T[3000006][3],sum[3000006]; 25 int cou; 26 void init() 27 { 28 cou=1; 29 memset(T,0,sizeof(T)); 30 memset(sum,0,sizeof(sum)); 31 } 32 void inser(int num) 33 { 34 int h=0; 35 for(int i=31; i>=0; i--) 36 { 37 if(T[h][(num>>i)&1]==0) 38 T[h][(num>>i)&1]=cou++; 39 h=T[h][(num>>i)&1]; 40 } 41 sum[h]=num; 42 } 43 int ask(int num) 44 { 45 int h=0; 46 for(int i=31; i>=0; i--) 47 { 48 int x=(num>>i)&1,sign=0; 49 if(x==0) sign=1; 50 if(T[h][sign]) h=T[h][sign]; 51 else h=T[h][x]; 52 } 53 return sum[h]; 54 } 55 }tire; 56 int main() 57 { 58 scanf("%d",&t); 59 for(int k=1; k<=t; k++) 60 { 61 tire.init(); 62 scanf("%d %d",&n,&m); 63 int exm; 64 for(int j=1; j<=n; j++) 65 { 66 scanf("%d",&exm); 67 tire.inser(exm); 68 } 69 printf("Case #%d:\n",k); 70 for(int j=1;j<=m;j++) 71 { 72 scanf("%d",&exm); 73 printf("%d\n",tire.ask(exm)); 74 } 75 } 76 return 0; 77 }
标签:lib iss logs 集合 程序设计 comm 异或 queue chmod
原文地址:http://www.cnblogs.com/hsd-/p/7277145.html