码迷,mamicode.com
首页 > 其他好文 > 详细

ICPC 2015 Changchun现场赛--Chip Factory

时间:2018-10-03 23:59:14      阅读:312      评论:0      收藏:0      [点我收藏+]

标签:factor   opened   tmp   ret   its   分享图片   target   get   eve   

题目链接:http://exam.upc.edu.cn/problem.php?id=9264

01字典树

技术分享图片
 1 #include <bits/stdc++.h>
 2 
 3 using namespace std;
 4 int n,tot,trie[70005][2],a[1005],cnt[70005];
 5 void init(int i)
 6 {
 7     trie[i][1]=trie[i][0]=0;
 8     cnt[i]=0;
 9 }
10 void add(int x,int id)
11 {
12     int now=0;
13     for(int i=31;i>=0;i--)
14     {
15         int p=0;
16         if(((1<<i)&x)!=0)   p=1;
17         if(!trie[now][p])
18         {
19             tot++;
20             trie[now][p]=tot;
21             init(tot);
22         }
23         now=trie[now][p];
24         cnt[now]+=id;
25     }
26 }
27 int query(int x)
28 {
29     int now=0,tmp=0;
30     for(int i=31;i>=0;i--)
31     {
32         int p=1;
33         if(((1<<i)&x)!=0)   p=0;
34         if(!trie[now][p]||cnt[trie[now][p]]<=0) now=trie[now][!p];
35         else{
36             tmp+=(1<<i);
37             now=trie[now][p];
38         }
39     }
40     return tmp;
41 }
42 int main()
43 {
44     int t;
45     scanf("%d",&t);
46     while(t--)
47     {
48         tot=0;
49         init(tot);
50         scanf("%d",&n);
51         for(int i=1;i<=n;i++)
52         {
53             scanf("%d",&a[i]);
54             add(a[i],1);
55         }
56         int ans=-1;
57         for(int i=1;i<=n;i++)
58         {
59             for(int j=i+1;j<=n;j++)
60             {
61                 add(a[i],-1);
62                 add(a[j],-1);
63                 ans=max(ans,query(a[i]+a[j]));
64                 add(a[i],1);
65                 add(a[j],1);
66             }
67         }
68         memset(cnt,0,sizeof(cnt));
69         printf("%d\n",ans);
70     }
71     return 0;
72 }
View Code

 

ICPC 2015 Changchun现场赛--Chip Factory

标签:factor   opened   tmp   ret   its   分享图片   target   get   eve   

原文地址:https://www.cnblogs.com/scott527407973/p/9738781.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!