HDU 5536 Chip Factory
2018-06-17 21:14:32来源:未知 阅读 ()
Chip Factory
Time Limit: 18000/9000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 4414 Accepted Submission(s):
1954
At the end of the day, he packages all the chips produced this day, and send it to wholesalers. More specially, he writes a checksum number on the package, this checksum is defined as below:
\max_{i,j,k} (s_i+s_j) \oplus s_k
which i,j,k are three different integers between 1 and n . And \oplus is symbol of bitwise XOR.
Can you help John calculate the checksum number of today?
The first line of each test case is an integer n , indicating the number of chips produced today. The next line has n integers s_1, s_2, .., s_n , separated with single space, indicating serial number of each chip.
1 \le T \le 1000
3 \le n \le 1000
0 \le s_i \le 10^9
There are at most 10 testcases with n > 100
#include<cstdio> #include<cmath> #include<algorithm> using namespace std; const int MAXN=1e6+10; inline int read() { char c=getchar();int x=0,f=1; while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();} while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();} return x*f; } #define debug(x) printf("%d",x); struct node { int val,ch[2]; node(){val=ch[0]=ch[1]=0;} void clear(){val=ch[0]=ch[1]=0;} }T[MAXN]; int a[MAXN],root=0,tot=0; void Insert(int v) { int now=root; for(int i=31;i>=0;i--) { int opt=(v&(1<<i))?1:0; if(!T[now].ch[opt]) T[now].ch[opt]=++tot; now=T[now].ch[opt]; T[now].val++; } } void Delet(int v) { int now=root; for(int i=31;i>=0;i--) { int opt=(v&(1<<i))?1:0; now=T[now].ch[opt]; T[now].val--; } } int Query(int v) { int ans=0,now=root; for(int i=31;i>=0;i--) { int opt=(v&(1<<i))?1:0; if(T[T[now].ch[opt^1]].val) ans+=1<<i,now=T[now].ch[opt^1]; else now=T[now].ch[opt]; } return ans; } int main() { freopen("a.in","r",stdin); int Test=read(); while(Test--) { int N=read(); for(int i=1;i<=N;i++) a[i]=read(); for(int i=1;i<=4*N;i++) T[i].clear(); for(int i=1;i<=N;i++) Insert(a[i]); int ans=0; for(int i=1;i<=N;i++) { for(int j=1;j<i;j++) { Delet(a[i]);Delet(a[j]); ans=max(ans,Query(a[i]+a[j])); Insert(a[i]);Insert(a[j]); } } printf("%d\n",ans); } return 0; }
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
上一篇:C++小游戏BrickHit
- HDU-2955-Robberies(0-1背包) 2020-03-30
- hdu1455 拼木棍(经典dfs) 2020-02-29
- anniversary party_hdu1520 2020-02-16
- hdu1062 text reverse 2020-01-27
- hdu4841 2020-01-26
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash