hdu 5536 Chip Factory 字典树+bitset 铜牌题
Posted smilesundream
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了hdu 5536 Chip Factory 字典树+bitset 铜牌题相关的知识,希望对你有一定的参考价值。
Chip Factory
Time Limit: 18000/9000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 1842 Accepted Submission(s): 833
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
chips today, the
-th chip produced this day has a serial number ![技术分享](https://image.cha138.com/20200809/d8549ac9a2bf4cccab275dd36fab0d66.jpg)
.
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:
![技术分享](https://image.cha138.com/20200809/41e38b8224684d24a64bdd72f536781e.jpg)
![技术分享](https://image.cha138.com/20200809/275c5b424bb94971b3bdf8f18ecc6fb7.jpg)
![技术分享](https://image.cha138.com/20200809/eb2afd8b575b4cedae68ff288188409c.jpg)
![技术分享](https://image.cha138.com/20200809/40e2e68b20ad410b9ac3b5d94690e274.jpg)
![技术分享](https://image.cha138.com/20200809/4d22590a7d7c4ee7abc7ac9871fc2bcd.jpg)
![技术分享](https://image.cha138.com/20200809/7a79be2b722041a4b043c778542d58e9.jpg)
![技术分享](https://image.cha138.com/20200809/4d22590a7d7c4ee7abc7ac9871fc2bcd.jpg)
![技术分享](https://image.cha138.com/20200809/d7df69020d2c4e3497b2597d4486e1cc.jpg)
![技术分享](https://image.cha138.com/20200809/2a4710646d7443b996b2b25f6a8b888c.jpg)
![技术分享](https://image.cha138.com/20200809/d8549ac9a2bf4cccab275dd36fab0d66.jpg)
![技术分享](https://image.cha138.com/20200809/40e2e68b20ad410b9ac3b5d94690e274.jpg)
![技术分享](https://image.cha138.com/20200809/428339f069b74aa18d3c5e7566312416.jpg)
![技术分享](https://image.cha138.com/20200809/d8549ac9a2bf4cccab275dd36fab0d66.jpg)
![技术分享](https://image.cha138.com/20200809/7a79be2b722041a4b043c778542d58e9.jpg)
![技术分享](https://image.cha138.com/20200809/b4228d42cde541bea538bb9f9fbaabe1.jpg)
![技术分享](https://image.cha138.com/20200809/92ed954770064e4582223c551e56c3cd.jpg)
![技术分享](https://image.cha138.com/20200809/d8549ac9a2bf4cccab275dd36fab0d66.jpg)
which![技术分享](https://image.cha138.com/20200809/ab94f4483b334ba4bb0c5820c0c9c034.jpg)
![技术分享](https://image.cha138.com/20200809/42f3725a505c469dbd3e1155cfc5726f.jpg)
![技术分享](https://image.cha138.com/20200809/01c95182c1ee4a24ba5f6520394e07d9.jpg)
![技术分享](https://image.cha138.com/20200809/42f3725a505c469dbd3e1155cfc5726f.jpg)
are three different integers between
and
. And
is symbol of bitwise XOR.
Can you help John calculate the checksum number of today?
![技术分享](https://image.cha138.com/20200809/82ec48380d55439aa21b921c0664e426.jpg)
![技术分享](https://image.cha138.com/20200809/ab94f4483b334ba4bb0c5820c0c9c034.jpg)
![技术分享](https://image.cha138.com/20200809/d8549ac9a2bf4cccab275dd36fab0d66.jpg)
![技术分享](https://image.cha138.com/20200809/40e2e68b20ad410b9ac3b5d94690e274.jpg)
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:
![技术分享](https://image.cha138.com/20200809/41e38b8224684d24a64bdd72f536781e.jpg)
![技术分享](https://image.cha138.com/20200809/275c5b424bb94971b3bdf8f18ecc6fb7.jpg)
![技术分享](https://image.cha138.com/20200809/eb2afd8b575b4cedae68ff288188409c.jpg)
![技术分享](https://image.cha138.com/20200809/40e2e68b20ad410b9ac3b5d94690e274.jpg)
![技术分享](https://image.cha138.com/20200809/4d22590a7d7c4ee7abc7ac9871fc2bcd.jpg)
![技术分享](https://image.cha138.com/20200809/7a79be2b722041a4b043c778542d58e9.jpg)
![技术分享](https://image.cha138.com/20200809/4d22590a7d7c4ee7abc7ac9871fc2bcd.jpg)
![技术分享](https://image.cha138.com/20200809/d7df69020d2c4e3497b2597d4486e1cc.jpg)
![技术分享](https://image.cha138.com/20200809/2a4710646d7443b996b2b25f6a8b888c.jpg)
![技术分享](https://image.cha138.com/20200809/d8549ac9a2bf4cccab275dd36fab0d66.jpg)
![技术分享](https://image.cha138.com/20200809/40e2e68b20ad410b9ac3b5d94690e274.jpg)
![技术分享](https://image.cha138.com/20200809/428339f069b74aa18d3c5e7566312416.jpg)
![技术分享](https://image.cha138.com/20200809/d8549ac9a2bf4cccab275dd36fab0d66.jpg)
![技术分享](https://image.cha138.com/20200809/7a79be2b722041a4b043c778542d58e9.jpg)
![技术分享](https://image.cha138.com/20200809/b4228d42cde541bea538bb9f9fbaabe1.jpg)
![技术分享](https://image.cha138.com/20200809/92ed954770064e4582223c551e56c3cd.jpg)
![技术分享](https://image.cha138.com/20200809/d8549ac9a2bf4cccab275dd36fab0d66.jpg)
![技术分享](https://image.cha138.com/20200809/d7df69020d2c4e3497b2597d4486e1cc.jpg)
which
![技术分享](https://image.cha138.com/20200809/ab94f4483b334ba4bb0c5820c0c9c034.jpg)
![技术分享](https://image.cha138.com/20200809/42f3725a505c469dbd3e1155cfc5726f.jpg)
![技术分享](https://image.cha138.com/20200809/01c95182c1ee4a24ba5f6520394e07d9.jpg)
![技术分享](https://image.cha138.com/20200809/42f3725a505c469dbd3e1155cfc5726f.jpg)
![技术分享](https://image.cha138.com/20200809/b96a65889f514d53868cd9b26ab8c53f.jpg)
![技术分享](https://image.cha138.com/20200809/ca5351ab6656434e8640baa8193db996.jpg)
![技术分享](https://image.cha138.com/20200809/82ec48380d55439aa21b921c0664e426.jpg)
![技术分享](https://image.cha138.com/20200809/92ed954770064e4582223c551e56c3cd.jpg)
Can you help John calculate the checksum number of today?
Input
The first line of input contains an integer
indicating the total number of test cases.
The first line of each test case is an integer
, indicating the number of chips produced today. The next line has
integers ![技术分享](https://image.cha138.com/20200809/d8549ac9a2bf4cccab275dd36fab0d66.jpg)
![技术分享](https://image.cha138.com/20200809/eaf4d51f0aed41ce8dfa5c86d86802fa.jpg)
![技术分享](https://image.cha138.com/20200809/42f3725a505c469dbd3e1155cfc5726f.jpg)
![技术分享](https://image.cha138.com/20200809/d8549ac9a2bf4cccab275dd36fab0d66.jpg)
![技术分享](https://image.cha138.com/20200809/b35304b1a0bd4e4cbd0e779e260977a3.jpg)
![技术分享](https://image.cha138.com/20200809/42f3725a505c469dbd3e1155cfc5726f.jpg)
![技术分享](https://image.cha138.com/20200809/c99524c0425844ad8832e08aee9c8ca5.jpg)
![技术分享](https://image.cha138.com/20200809/c99524c0425844ad8832e08aee9c8ca5.jpg)
![技术分享](https://image.cha138.com/20200809/42f3725a505c469dbd3e1155cfc5726f.jpg)
![技术分享](https://image.cha138.com/20200809/d8549ac9a2bf4cccab275dd36fab0d66.jpg)
, separated with single space, indicating serial number of each chip.
![技术分享](https://image.cha138.com/20200809/ca5351ab6656434e8640baa8193db996.jpg)
![技术分享](https://image.cha138.com/20200809/a2bd804604c9435db998946764d4faff.jpg)
![技术分享](https://image.cha138.com/20200809/f29396da609444d9a6877d342ce53c34.jpg)
![技术分享](https://image.cha138.com/20200809/a2bd804604c9435db998946764d4faff.jpg)
![技术分享](https://image.cha138.com/20200809/ca5351ab6656434e8640baa8193db996.jpg)
![技术分享](https://image.cha138.com/20200809/85d1c9d2cfd741938cf44676c8159b06.jpg)
![技术分享](https://image.cha138.com/20200809/85d1c9d2cfd741938cf44676c8159b06.jpg)
![技术分享](https://image.cha138.com/20200809/85d1c9d2cfd741938cf44676c8159b06.jpg)
![技术分享](https://image.cha138.com/20200809/b7c8e6fd945a4fcdbe119db08fc4aec1.jpg)
![技术分享](https://image.cha138.com/20200809/a2bd804604c9435db998946764d4faff.jpg)
![技术分享](https://image.cha138.com/20200809/82ec48380d55439aa21b921c0664e426.jpg)
![技术分享](https://image.cha138.com/20200809/a2bd804604c9435db998946764d4faff.jpg)
![技术分享](https://image.cha138.com/20200809/ca5351ab6656434e8640baa8193db996.jpg)
![技术分享](https://image.cha138.com/20200809/85d1c9d2cfd741938cf44676c8159b06.jpg)
![技术分享](https://image.cha138.com/20200809/85d1c9d2cfd741938cf44676c8159b06.jpg)
![技术分享](https://image.cha138.com/20200809/85d1c9d2cfd741938cf44676c8159b06.jpg)
![技术分享](https://image.cha138.com/20200809/85d1c9d2cfd741938cf44676c8159b06.jpg)
![技术分享](https://image.cha138.com/20200809/a2bd804604c9435db998946764d4faff.jpg)
![技术分享](https://image.cha138.com/20200809/d8549ac9a2bf4cccab275dd36fab0d66.jpg)
![技术分享](https://image.cha138.com/20200809/40e2e68b20ad410b9ac3b5d94690e274.jpg)
![技术分享](https://image.cha138.com/20200809/a2bd804604c9435db998946764d4faff.jpg)
![技术分享](https://image.cha138.com/20200809/ca5351ab6656434e8640baa8193db996.jpg)
![技术分享](https://image.cha138.com/20200809/85d1c9d2cfd741938cf44676c8159b06.jpg)
![技术分享](https://image.cha138.com/20200809/aabe1642a85f4f899b2866fa8f4857c6.jpg)
There are at most![技术分享](https://image.cha138.com/20200809/ca5351ab6656434e8640baa8193db996.jpg)
testcases with ![技术分享](https://image.cha138.com/20200809/82ec48380d55439aa21b921c0664e426.jpg)
![技术分享](https://image.cha138.com/20200809/b51a0e58bca1461996e53fd1c2d38881.jpg)
![技术分享](https://image.cha138.com/20200809/ca5351ab6656434e8640baa8193db996.jpg)
![技术分享](https://image.cha138.com/20200809/85d1c9d2cfd741938cf44676c8159b06.jpg)
![技术分享](https://image.cha138.com/20200809/85d1c9d2cfd741938cf44676c8159b06.jpg)
![技术分享](https://image.cha138.com/20200809/f29396da609444d9a6877d342ce53c34.jpg)
The first line of each test case is an integer
![技术分享](https://image.cha138.com/20200809/82ec48380d55439aa21b921c0664e426.jpg)
![技术分享](https://image.cha138.com/20200809/82ec48380d55439aa21b921c0664e426.jpg)
![技术分享](https://image.cha138.com/20200809/d8549ac9a2bf4cccab275dd36fab0d66.jpg)
![技术分享](https://image.cha138.com/20200809/eaf4d51f0aed41ce8dfa5c86d86802fa.jpg)
![技术分享](https://image.cha138.com/20200809/42f3725a505c469dbd3e1155cfc5726f.jpg)
![技术分享](https://image.cha138.com/20200809/d8549ac9a2bf4cccab275dd36fab0d66.jpg)
![技术分享](https://image.cha138.com/20200809/b35304b1a0bd4e4cbd0e779e260977a3.jpg)
![技术分享](https://image.cha138.com/20200809/42f3725a505c469dbd3e1155cfc5726f.jpg)
![技术分享](https://image.cha138.com/20200809/c99524c0425844ad8832e08aee9c8ca5.jpg)
![技术分享](https://image.cha138.com/20200809/c99524c0425844ad8832e08aee9c8ca5.jpg)
![技术分享](https://image.cha138.com/20200809/42f3725a505c469dbd3e1155cfc5726f.jpg)
![技术分享](https://image.cha138.com/20200809/d8549ac9a2bf4cccab275dd36fab0d66.jpg)
![技术分享](https://image.cha138.com/20200809/ec56bfc0312f4adba1c5b36855233d3c.jpg)
![技术分享](https://image.cha138.com/20200809/ca5351ab6656434e8640baa8193db996.jpg)
![技术分享](https://image.cha138.com/20200809/a2bd804604c9435db998946764d4faff.jpg)
![技术分享](https://image.cha138.com/20200809/f29396da609444d9a6877d342ce53c34.jpg)
![技术分享](https://image.cha138.com/20200809/a2bd804604c9435db998946764d4faff.jpg)
![技术分享](https://image.cha138.com/20200809/ca5351ab6656434e8640baa8193db996.jpg)
![技术分享](https://image.cha138.com/20200809/85d1c9d2cfd741938cf44676c8159b06.jpg)
![技术分享](https://image.cha138.com/20200809/85d1c9d2cfd741938cf44676c8159b06.jpg)
![技术分享](https://image.cha138.com/20200809/85d1c9d2cfd741938cf44676c8159b06.jpg)
![技术分享](https://image.cha138.com/20200809/b7c8e6fd945a4fcdbe119db08fc4aec1.jpg)
![技术分享](https://image.cha138.com/20200809/a2bd804604c9435db998946764d4faff.jpg)
![技术分享](https://image.cha138.com/20200809/82ec48380d55439aa21b921c0664e426.jpg)
![技术分享](https://image.cha138.com/20200809/a2bd804604c9435db998946764d4faff.jpg)
![技术分享](https://image.cha138.com/20200809/ca5351ab6656434e8640baa8193db996.jpg)
![技术分享](https://image.cha138.com/20200809/85d1c9d2cfd741938cf44676c8159b06.jpg)
![技术分享](https://image.cha138.com/20200809/85d1c9d2cfd741938cf44676c8159b06.jpg)
![技术分享](https://image.cha138.com/20200809/85d1c9d2cfd741938cf44676c8159b06.jpg)
![技术分享](https://image.cha138.com/20200809/85d1c9d2cfd741938cf44676c8159b06.jpg)
![技术分享](https://image.cha138.com/20200809/a2bd804604c9435db998946764d4faff.jpg)
![技术分享](https://image.cha138.com/20200809/d8549ac9a2bf4cccab275dd36fab0d66.jpg)
![技术分享](https://image.cha138.com/20200809/40e2e68b20ad410b9ac3b5d94690e274.jpg)
![技术分享](https://image.cha138.com/20200809/a2bd804604c9435db998946764d4faff.jpg)
![技术分享](https://image.cha138.com/20200809/ca5351ab6656434e8640baa8193db996.jpg)
![技术分享](https://image.cha138.com/20200809/85d1c9d2cfd741938cf44676c8159b06.jpg)
![技术分享](https://image.cha138.com/20200809/aabe1642a85f4f899b2866fa8f4857c6.jpg)
There are at most
![技术分享](https://image.cha138.com/20200809/ca5351ab6656434e8640baa8193db996.jpg)
![技术分享](https://image.cha138.com/20200809/85d1c9d2cfd741938cf44676c8159b06.jpg)
![技术分享](https://image.cha138.com/20200809/82ec48380d55439aa21b921c0664e426.jpg)
![技术分享](https://image.cha138.com/20200809/b51a0e58bca1461996e53fd1c2d38881.jpg)
![技术分享](https://image.cha138.com/20200809/ca5351ab6656434e8640baa8193db996.jpg)
![技术分享](https://image.cha138.com/20200809/85d1c9d2cfd741938cf44676c8159b06.jpg)
![技术分享](https://image.cha138.com/20200809/85d1c9d2cfd741938cf44676c8159b06.jpg)
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个整型数(n<=1e3),现在可以从其中选出s1,s2,s3三个数字,要求求出(s1+s2)^s3的最大值,至多
1e3组测试数据。
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <iostream>
#include <cmath>
#include <map>
#include <bitset>
#include <stack>
#include <queue>
#include <vector>
#include <bitset>
#include <set>
#define MM(a,b) memset(a,b,sizeof(a));
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
#define CT continue
#define SC scanf
const int N=1e3+10;
int ch[40*N][3];
int a[N],sz,num[40*N],val[40*N];
bitset<32> v;
void add(int k)
{
int p=0;
for(int i=30;i>=0;i--){
int id=v[i];
if(ch[p][id]==-1) ch[p][id]=++sz;
p=ch[p][id];
num[p]+=k;
}
if(k!=-1) val[p]=v.to_ullong();//返回bitset的值
}
int query()
{
int p=0;
for(int i=30;i>=0;i--){
int id=v[i],ano=ch[p][!id];
if(ano!=-1&&num[ano]!=0) p=ano;
else p=ch[p][id];
}
return val[p];
}
int main()
{
int cas,n;
SC("%d",&cas);
while(cas--){
MM(ch,-1);MM(num,0);sz=0;
SC("%d",&n);
for(int i=1;i<=n;i++){
SC("%d",&a[i]);
v=a[i];
add(1);
}
int ans=0;
for(int i=1;i<=n;i++){
v=a[i];add(-1);
for(int j=i+1;j<=n;j++){
v=a[j];add(-1);
v=a[i]+a[j];
ans=max(ans,(a[i]+a[j])^query());
v=a[j];add(1);
}
v=a[i];add(1);
}
printf("%d\n",ans);
}
return 0;
}
错因:刚开始想到的是枚举下s1+s2,然后,,插入s3,,,但是发现根本处理不了重合的情况,,,。。
解答:其实先依次添加元素建好字典树后,,可以n^2的枚举s1+s2,同时在字典树中抹去这两个元素,
这时再插入s3,,每次操作完成后都将s1,s2再添加进去。。
以上是关于hdu 5536 Chip Factory 字典树+bitset 铜牌题的主要内容,如果未能解决你的问题,请参考以下文章
HDU - 5536 Chip Factory 字典树的删除