标签:The 保存 inpu 最大 正整数 memory eof tle limit
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 132768/132768 K (Java/Others)
Total Submission(s): 4144 Accepted Submission(s): 1810
#include <iostream> #include <algorithm> #include <cstring> #include <cstdio> #include <vector> #include <queue> #include <stack> #include <cstdlib> #include <iomanip> #include <cmath> #include <cassert> #include <ctime> #include <map> #include <set> using namespace std; #pragma comment(linker, "/stck:1024000000,1024000000") #define lowbit(x) (x&(-x)) #define max(x,y) (x>=y?x:y) #define min(x,y) (x<=y?x:y) #define MAX 100000000000000000 #define MOD 1000000007 #define pi acos(-1.0) #define ei exp(1) #define PI 3.1415926535897932384626433832 #define ios() ios::sync_with_stdio(true) #define INF 0x3f3f3f3f #define mem(a) (memset(a,0,sizeof(a))) typedef long long ll; int t,n,m,T; struct tree { struct tree *next[2]; int val; tree() { val=0; for(int i=0;i<2;i++) next[i]=NULL; } }; tree *root; void insert(int x) { int a[34]; tree *p=root,*q; for(int i=0;i<32;i++) a[i]=(x&(1<<i))?1:0; for(int i=31;i>=0;i--) { if(p->next[a[i]]==NULL) { q=new tree(); p->next[a[i]]=q; } p=p->next[a[i]]; } p->val=x; } void query(int x) { tree *p=root; int a[34]; for(int i=0;i<32;i++) a[i]=x&(1<<i)?1:0; for(int i=31;i>=0;i--) { if(!p->next[a[i]^1]) p=p->next[a[i]]; else p=p->next[a[i]^1]; } printf("%d\n",p->val); } void del(tree *root) { for(int i=0;i<2;i++) if(root->next[i]!=NULL) del(root->next[i]); free(root); } int main() { scanf("%d",&t); T=t; while(t--) { root=new tree(); scanf("%d%d",&n,&m); for(int i=0,x;i<n;i++) { scanf("%d",&x); insert(x); } printf("Case #%d:\n",T-t); for(int i=0,x;i<m;i++) { scanf("%d",&x); query(x); } del(root); } return 0; }
标签:The 保存 inpu 最大 正整数 memory eof tle limit
原文地址:https://www.cnblogs.com/shinianhuanniyijuhaojiubujian/p/9096962.html