1. 程式人生 > >HDU 5536 Chip Factory

HDU 5536 Chip Factory

font ava display algo acm getchar 暴力 width miss

Chip Factory

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


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 s技術分享圖片i技術分享圖片技術分享圖片 .

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:
max技術分享圖片i,j,k技術分享圖片(s技術分享圖片i技術分享圖片+s技術分享圖片j技術分享圖片)s技術分享圖片
k技術分享圖片技術分享圖片

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 s技術分享圖片1技術分享圖片,s技術分享圖片2技術分享圖片,..,s技術分享圖片n技術分享圖片技術分享圖片 , separated with single space, indicating serial number of each chip.

1T1000技術分享圖片
3n1000技術分享圖片
0s技術分享圖片i技術分享圖片10技術分享圖片9技術分享圖片技術分享圖片
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

Source 2015ACM/ICPC亞洲區長春站-重現賽(感謝東北師大)

Recommend hujie | We have carefully selected several similar problems for you: 6263 6262 6261 6260 6259 讀不懂英語好吃虧啊。 一開始一直在想前面的$s_i+s_j$怎麽搞。 後來看了一下輸入,這麽不就是個逗比題麽。。 $s_i+s_j$只要暴力枚舉就好,建一顆01Trie樹,查詢最大的時候優先走不一樣的 查詢之前先把$s_i,s_j$刪除 查完之後再加進去
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
const int MAXN=1e6+10;
inline int read()
{
    char c=getchar();int x=0,f=1;
    while(c<0||c>9){if(c==-)f=-1;c=getchar();}
    while(c>=0&&c<=9){x=x*10+c-0;c=getchar();}
    return x*f;
}
#define debug(x) printf("%d",x);
struct node
{
    int val,ch[2];
    node(){val=ch[0]=ch[1]=0;}
    void clear(){val=ch[0]=ch[1]=0;}
}T[MAXN];
int a[MAXN],root=0,tot=0;
void Insert(int v)
{
    int now=root;
    for(int i=31;i>=0;i--)
    {
        int opt=(v&(1<<i))?1:0;
        if(!T[now].ch[opt]) 
            T[now].ch[opt]=++tot;
        now=T[now].ch[opt];
        T[now].val++;
     }
}
void Delet(int v)
{
    int now=root;
    for(int i=31;i>=0;i--)
    {
        int opt=(v&(1<<i))?1:0;
        now=T[now].ch[opt];
        T[now].val--;
     }
}
int Query(int v)
{
    int ans=0,now=root;
    for(int i=31;i>=0;i--)
    {
        int opt=(v&(1<<i))?1:0;
        if(T[T[now].ch[opt^1]].val) 
            ans+=1<<i,now=T[now].ch[opt^1];
        else 
            now=T[now].ch[opt];
    }
    return ans;
}
int main()
{
    freopen("a.in","r",stdin);
    int Test=read();
    while(Test--)
    {
        int N=read();
        for(int i=1;i<=N;i++) a[i]=read();
        for(int i=1;i<=4*N;i++) 
            T[i].clear();
        for(int i=1;i<=N;i++) 
            Insert(a[i]);
        int ans=0;
        for(int i=1;i<=N;i++)
        {
            for(int j=1;j<i;j++)
            {
                Delet(a[i]);Delet(a[j]);
                ans=max(ans,Query(a[i]+a[j]));
                Insert(a[i]);Insert(a[j]);
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}

HDU 5536 Chip Factory