地址:http://acm.split.hdu.edu.cn/showproblem.php?pid=5536

题目:

Chip Factory

Time Limit: 18000/9000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 2044    Accepted Submission(s): 919

Problem Description
John is a manager of a CPU chip factory, the factory produces lots of chips everyday. To manage large amounts of products, every processor has a serial number. More specifically, the factory produces n chips today, the i-th chip produced this day has a serial number si.

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:

maxi,j,k(si+sj)⊕sk

which i,j,k are three different integers between 1 and n. And ⊕ is symbol of bitwise XOR.

Can you help John calculate the checksum number of today?

 
Input
The first line of input contains an integer T indicating the total number of test cases.

The first line of each test case is an integer n, indicating the number of chips produced today. The next line has n integers s1,s2,..,sn, separated with single space, indicating serial number of each chip.

1≤T≤1000
3≤n≤1000
0≤si≤109
There are at most 10 testcases with n>100

 
Output
For each test case, please output an integer indicating the checksum number in a line.
 
Sample Input
2
3
1 2 3
3
100 200 300
 
Sample Output
6
400
 思路:这题居然可以N^3爆过去,我也是惊呆了==,数据太水了吧。正解是01trie。
暴力代码:
#include<stdio.h>
int a[];
int max(int ta,int b)
{
if(ta>b)
return ta;
return b;
}
int sc(int ta,int tb,int tc,int ans)
{
return max(ans,(ta+tb)^tc);
}
int main(void)
{
int t,n;
scanf("%d",&t);
while(t--)
{
int ans=;
scanf("%d",&n);
for(int i=;i<=n;i++)
scanf("%d",&a[i]);
for(int i=;i<=n;i++)
for(int j=i+;j<=n;j++)
for(int k=j+;k<=n;k++)
ans=sc(a[i],a[j],a[k],ans),ans=sc(a[j],a[k],a[i],ans),ans=sc(a[i],a[k],a[j],ans);
printf("%d\n",ans);
}
return ;
}

01trie代码:

#include <stdio.h>
#include <string.h>
struct Trie
{
int root, tot, next[][], cnt[], end[]; inline int Newnode()
{
memset(next[tot], -, sizeof(next[tot]));
cnt[tot] = ;
end[tot] = ;
return tot ++;
} inline void Init()
{
tot = ;
root = Newnode();
} inline void Insert(int x)
{
int p = root;
cnt[p] ++;
for(int i = ; i >= ; i --)
{
int idx = (( << i) & x) ? : ;
if(next[p][idx] == -)
next[p][idx] = Newnode();
p = next[p][idx];
cnt[p] ++;
}
end[p] = x;
} inline void Del(int x)
{
int p = root;
cnt[p] --;
for(int i = ; i >= ; i --)
{
int idx = (( << i) & x) ? : ;
p = next[p][idx];
cnt[p] --;
}
} inline int Search(int x)
{
int p = root;
for(int i = ; i >= ; i --)
{
int idx = (( << i) & x) ? : ;
if(idx == )
{
if(next[p][] != - && cnt[next[p][]])
p = next[p][];
else
p = next[p][];
}
else
{
if(next[p][] != - && cnt[next[p][]])
p = next[p][];
else
p = next[p][];
}
}
return x ^ end[p];
}
}tr;
int max(int ta,int tb)
{
return ta>=tb?ta:tb;
}
int a[];
int main(void)
{
int t;
scanf("%d",&t);
while(t--)
{
int n,ans=;scanf("%d",&n);
tr.Init();
for(int i=;i<=n;i++)
scanf("%d",&a[i]),tr.Insert(a[i]);
for(int i=;i<=n;i++)
for(int j=i+;j<=n;j++)
{
tr.Del(a[i]),tr.Del(a[j]);
ans=max(ans,tr.Search(a[i]+a[j]));
tr.Insert(a[i]),tr.Insert(a[j]);
}
printf("%d\n",ans);
}
return ;
}

hdu5269 Chip Factory的更多相关文章

  1. 2015ACM/ICPC亚洲区长春站 J hdu 5536 Chip Factory

    Chip Factory Time Limit: 18000/9000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)T ...

  2. HDU 5536 Chip Factory 字典树

    Chip Factory Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid= ...

  3. HDU 5536 Chip Factory 字典树+贪心

    给你n个数,a1....an,求(ai+aj)^ak最大的值,i不等于j不等于k 思路:先建字典树,暴力i,j每次删除他们,然后贪心找k,再恢复i,j,每次和答案取较大的,就是答案,有关异或的貌似很多 ...

  4. hdu 5536 Chip Factory (01 Trie)

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=5536 题面; Chip Factory Time Limit: 18000/9000 MS (Java/O ...

  5. Chip Factory(01字典树)

    Chip Factory http://acm.hdu.edu.cn/showproblem.php?pid=5536 Time Limit: 18000/9000 MS (Java/Others)  ...

  6. hdu5536 Chip Factory 字典树+暴力 处理异或最大 令X=(a[i]+a[j])^a[k], i,j,k都不同。求最大的X。

    /** 题目:hdu5536 Chip Factory 链接:http://acm.hdu.edu.cn/showproblem.php?pid=5536 题意:给定n个数,令X=(a[i]+a[j] ...

  7. HDU 5536 Chip Factory 【01字典树删除】

    题目传送门:http://acm.hdu.edu.cn/showproblem.php?pid=5536 Chip Factory Time Limit: 18000/9000 MS (Java/Ot ...

  8. ACM Changchun 2015 J. Chip Factory

    John is a manager of a CPU chip factory, the factory produces lots of chips everyday. To manage larg ...

  9. HDU 5536 Chip Factory

    Chip Factory Time Limit: 18000/9000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)T ...

随机推荐

  1. Winjs – 微软开源技术发布的 JavaScript 组件集

    Winjs 是由微软开源技术的开发者推出的一组 JavaScript 组件,包括 ListView.ListView.Tooltip.DatePicker.Ratings 等等,帮助 Web 开发人员 ...

  2. WPS 从今以后我再也不会用了 记录一下!

    一个双十一,金山忙得不亦乐乎,就往桌面上添加图标. 卸载掉你!!!!! 一些令人厌恶的动作: 1.强制弹广告. 2.强制弹新闻窗口:WPS热点:无法设置不再弹出. 3.强制自动升级.删了还会有. 4. ...

  3. 阿帕奇apache服务器和webDav服务器快速配置。

    当自己在家敲代码需要发请求时,就可以配置本地apache,Mac电脑自带的服务器.这个比windows上的本地服务器还要好用,下面写下最快速配置方案. 0.在开始之前需要给自己的电脑设置下开机密码,想 ...

  4. List集合概述

    上篇总结了Set集合,这回总结下List集合....先来框架图: 一.List集合 List集合代表一个元素有序,可重复的集合,集合中每个元素都有对应的顺序索引.List接口中增加了一些根据索引操作元 ...

  5. 拓展:使用终端创建、编译、链接OC…

    本文介绍一下如何使用Mac OS X自带终端快速创建.编译.链接OC程序. 1.打开终端 顺序:打开Finder——应用程序——实用工具——终端 2.打开需要存放 .m 文件的路径(比如我需要放到桌面 ...

  6. iOS关于CAShapeLayer与UIBezierPath的知识内容

    使用CAShapeLayer与UIBezierPath可以实现不在view的drawRect方法中就画出一些想要的图形 . 1:UIBezierPath: UIBezierPath是在 UIKit 中 ...

  7. Java中的两个关键字——super、this

    Java中的两个关键字——super.this 神话丿小王子的博客主页 一.super super 是java中方的一个关键字,用它可以引用父类中的成员: super可用于访问父类中定义的属性 sup ...

  8. iOS中block的使用、实现底层、循环引用、存储位置

    一.整体介绍 定义:C语言的匿名函数,

  9. iOS中的UI

    • 不管你是学习android开发还是iOS开发• 都建议先学习UI,原因如下:UI是app的根基:⼀一个app应该是先有UI界⾯面,然后在UI的基础上增加实⽤用功能 UI相对简单易学:UI普遍是学 ...

  10. Android按键事件处理流程 -- KeyEvent

    刚接触Android开发的时候,对touch.key事件的处理总是一知半解,一会是Activity里的方法,一会是各种View 中的,自己始终不清楚到底哪个在先哪个在后,总之对整个处理流程没能很好的把 ...