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 ...
随机推荐
- [deviceone开发]-do_Camera的简单示例
一.简介 do_Camera组件是通过拍照裁剪来生成图片的组件,这个示例直观的展示组件基本的使用方式 二.效果图 三.相关下载 https://github.com/do-project/code4d ...
- jQuery 重要的知识点归纳
jQuery 对象 jQuery 对象就是通过 jQuery 包装 DOM 对象后产生的对象. jQuery 对象是 jQuery 独有的. 只有 jQuery 对象才能使用 jQuery 的方法,在 ...
- 送给我的朋友——Cry on my shoulder
If the hero never comes to you如果你的真命天子仍未来到 If you need someone you"re feeling blue如果你情绪低落需要有人陪伴 ...
- Hadoop出现 native snappy library not available: SnappyCompressor has not been loaded的解决办法
我目前测试环境是Hadoop 2.7.1, 搭建群集之后经常出现错误“native snappy library not available: SnappyCompressor has not bee ...
- Problem with WinRM on Exchange 2013 Management Shell and Exchange Toolbox on a new exchange 2013 with CAFE and BE on single server installation
While deploying MS Exchange 2013 I experienced issues with accessing the Exchange Management Shell a ...
- 【Openlayers3】在地图上添加highcharts图表
今天试用了一下ol3,效果很是不错! ol3中有个ol.Overlay,使用这个类我们可以在地图中添加各种html要素. 下面我们在地图中添加一个饼图 html中添加一个div容器: <div ...
- 使用cocoaPods一键集成第三方登录(新浪微博,qq,微信)
第三方登录是现在app很常用的功能,而这个功能我已经写过两三次了...每次都写大同小异的代码真的是很痛苦,而且每次都要根据说明去添加那些依赖库,配置linkFlag什么的,完全是体力活,所以一直想把这 ...
- 颜色线性渐变-CAGradientLayer
我们先来看一下效果图吧: 其实,就是一个颜色的线性渐变,使用CAGradientLayer很容易就能实现.由于代码很简单,就不做过多讲解了,直接看代码吧. import UIKit class Vie ...
- setTimeout和setInterval
setTimeout(methodName, interval); //间隔时间单位为毫秒,表示interval毫秒后执行方法methodName setInterval(methodName, in ...
- MySQL 常见的sql命令
注意事项: 1.sql 使用单引号来环绕文本值(大部分数据库系统也接受双引号).如果是数值,请不要使用引号. 一.数据库 1.创建数据库 CREATE DATABASE lesson ; 创建一个名字 ...