hdu5269 Chip Factory
地址: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
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:
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?
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
#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的更多相关文章
- 2015ACM/ICPC亚洲区长春站 J hdu 5536 Chip Factory
Chip Factory Time Limit: 18000/9000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)T ...
- HDU 5536 Chip Factory 字典树
Chip Factory Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid= ...
- HDU 5536 Chip Factory 字典树+贪心
给你n个数,a1....an,求(ai+aj)^ak最大的值,i不等于j不等于k 思路:先建字典树,暴力i,j每次删除他们,然后贪心找k,再恢复i,j,每次和答案取较大的,就是答案,有关异或的貌似很多 ...
- hdu 5536 Chip Factory (01 Trie)
链接:http://acm.hdu.edu.cn/showproblem.php?pid=5536 题面; Chip Factory Time Limit: 18000/9000 MS (Java/O ...
- Chip Factory(01字典树)
Chip Factory http://acm.hdu.edu.cn/showproblem.php?pid=5536 Time Limit: 18000/9000 MS (Java/Others) ...
- 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] ...
- HDU 5536 Chip Factory 【01字典树删除】
题目传送门:http://acm.hdu.edu.cn/showproblem.php?pid=5536 Chip Factory Time Limit: 18000/9000 MS (Java/Ot ...
- 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 ...
- HDU 5536 Chip Factory
Chip Factory Time Limit: 18000/9000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)T ...
随机推荐
- Vanilla Masker – 功能强大的输入过滤插件
Vanilla Masker 是一个纯 JavaScript 实现的输入内容过滤和自动转换插件.现在你可以使用一个简单而纯粹的 JavaScript 库来控制你的 input 元素,而不需要加载 jQ ...
- 轻松掌握:JavaScript装饰者模式
装饰者模式 在传统的面向对象语言中,给对象添加功能常常使用继承的方式,但继承的方式会带来问题:当父类改变时,他的所有子类都将随之改变. 当JavaScript脚本运行时,在一个对象中(或他的原型上)增 ...
- 优秀的CSS框架---bootstrap
Bootstrap是Twitter推出的一个用于前端开发的开源工具包.它 由Twitter的设计师Mark Otto和Jacob Thornton合作开发,是一个CSS/HTML框架.现在在网上已经有 ...
- 后台运行进程(background job)
在一些日常业务中,总有一些长时间处理的任务,系统运行这些任务需要一晚甚至一个周末. 这就需要后台运行单元(background work process)来完成,而且其是不会发生超时(time out ...
- RPM命令学习
在centos中安装jdk,原本是要按照jdk1.7,结果装纯1.8,用的rpm安装包. 安装命令 rpm -ivh jdk-8u65-linux-x64.rpm 查询命令 rpm -qa|grep ...
- 愚人节大狂欢 – ADN DevBlog谎话连篇友谊赛
愚人节过去了,你被捉弄了没有? :) 借这个机会,ADN的哥们儿也发泄狂欢了一把,我们4月1号当天在ADN DevBlog上发了一堆谎话连篇的blog,没有一个说实话的,哈哈.这是我们team内部进行 ...
- 图形学理论知识 BRDF 双向反射分布函数(Bidirectional Reflectance Distribution Function)
图形学理论知识 BRDF 双向反射分布函数 Bidirectional Reflectance Distribution Function BRDF理论 BRDF表示的是双向反射分布函数(Bidire ...
- 【代码笔记】iOS-读取一段文字
一,效果图. 二,工程图. 三,代码. RootViewController.m #import "RootViewController.h" @interface RootVie ...
- scanf函数
一. 变量的内存分析 1. 字节和地址 为了更好地理解变量在内存中的存储细节,先来认识一下内存中的“字节”和“地址”. 1> 内存以“字节为单位” 0x表示的是十六进制,不用过于纠结,能看懂这些 ...
- 手机屏幕滑动效果框架——flipsnap
下午有时间,研究了下手机网页开发方面的内容.其中关于手机手势滑屏操作.发现有比较好的jquery 插件--flipsnap. 官方网站:http://pxgrid.github.com/js-flip ...