博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU 5536 Chip Factory 字典树
阅读量:5051 次
发布时间:2019-06-12

本文共 4902 字,大约阅读时间需要 16 分钟。

Chip Factory

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

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

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?

Under two situations the player could score one point.

⋅1. If you touch a buoy before your opponent, you will get one point. For example if your opponent touch the buoy #2 before you after start, he will score one point. So when you touch the buoy #2, you won't get any point. Meanwhile, you cannot touch buoy #3 or any other buoys before touching the buoy #2.
⋅2. Ignoring the buoys and relying on dogfighting to get point. If you and your opponent meet in the same position, you can try to fight with your opponent to score one point. For the proposal of game balance, two players are not allowed to fight before buoy #2 is touched by anybody.
There are three types of players.
Speeder: As a player specializing in high speed movement, he/she tries to avoid dogfighting while attempting to gain points by touching buoys.
Fighter: As a player specializing in dogfighting, he/she always tries to fight with the opponent to score points. Since a fighter is slower than a speeder, it's difficult for him/her to score points by touching buoys when the opponent is a speeder.
All-Rounder: A balanced player between Fighter and Speeder.
There will be a training match between Asuka (All-Rounder) and Shion (Speeder).
Since the match is only a training match, the rules are simplified: the game will end after the buoy #1 is touched by anybody. Shion is a speed lover, and his strategy is very simple: touch buoy #2,#3,#4,#1 along the shortest path.
Asuka is good at dogfighting, so she will always score one point by dogfighting with Shion, and the opponent will be stunned for T seconds after dogfighting. Since Asuka is slower than Shion, she decides to fight with Shion for only one time during the match. It is also assumed that if Asuka and Shion touch the buoy in the same time, the point will be given to Asuka and Asuka could also fight with Shion at the buoy. We assume that in such scenario, the dogfighting must happen after the buoy is touched by Asuka or Shion.
The speed of Asuka is V1 m/s. The speed of Shion is V2 m/s. Is there any possibility for Asuka to win the match (to have higher score)?

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

HINT

 

题意

给你100组test,然后每组数据有1000个数,然后让你求(ai+aj)^ak的最大值,i!=j!=k

题解:

比较裸的字典树,写一个删除和添加操作就好了

代码

 

#include
#include
#include
using namespace std;const int maxn = 1000 + 10;const int maxnode = 100000 + 10;int a[maxn];int ch[maxnode][2];int val[maxnode];int sz;void init(){ sz=1; memset(ch[0],0,sizeof(ch[0])); memset(val,0,sizeof(val));}void add(int x,int v){ int p = 0; for(int i=31;i>=0;i--) { int id = (x>>i)&1; if(ch[p][id]==0) { memset(ch[sz],0,sizeof(ch[sz])); val[sz]=0; ch[p][id]=sz++; } p = ch[p][id]; val[p]+=v; }}int match(int x){ int ans = 0,u = 0; x = ~x; for(int i=31;i>=0;i--) { ans*=2; int id = (x>>i)&1; if(ch[u][id]&&val[ch[u][id]]) { ans++; u = ch[u][id]; } else u = ch[u][1-id]; } return ans;}int main(){ int t;scanf("%d",&t); while(t--) { init(); int n;scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d",&a[i]); for(int i=1;i<=n;i++) add(a[i],1); int ans = 0; for(int i=1;i<=n;i++) { add(a[i],-1); for(int j=i+1;j<=n;j++) { add(a[j],-1); ans = max(ans,match(a[i]+a[j])); add(a[j],1); } add(a[i],1); } printf("%d\n",ans); }}

 

转载于:https://www.cnblogs.com/qscqesze/p/4955980.html

你可能感兴趣的文章
嵌入式Linux驱动学习之路(十)字符设备驱动-my_led
查看>>
【NOIP模拟】密码
查看>>
java容器---------手工实现Linkedlist 链表
查看>>
three.js 性能优化的几种方法
查看>>
《梦断代码》读书笔记(三)
查看>>
FreeMarker解析json数据
查看>>
Java8 Lambda表达应用 -- 单线程游戏server+异步数据库操作
查看>>
次序+“选择不重复的记录”(3)——最大记录
查看>>
Codeforces 450 C. Jzzhu and Chocolate
查看>>
[Unity3D]Unity3D游戏开发MatchTarget的作用攀登效果实现
查看>>
ACdream 1115 Salmon And Cat (找规律&amp;&amp;打表)
查看>>
JSON、JSONP、Ajax的区别
查看>>
AngularJS学习篇(一)
查看>>
关于Xshell无法连接centos6.4的问题
查看>>
css3动画——基本准则
查看>>
javaweb常识
查看>>
Java注解
查看>>
web自己主动保存表单
查看>>
一个小的日常实践——高速Fibonacci数算法
查看>>
机器学些技法(9)--Decision Tree
查看>>