HDU 5536 Chip Factory (dictionary tree)

Source: Internet
Author: User

Topic Stamp This

Test Instructions: give you the number of N, choose three number A,b,c, then (a+b) ^c, the value of this equation is the largest.

Ideas: If you come to three for the loop, decisive tle, so think of the dictionary tree, is to put all the numbers into the first, when the query to determine the number of the two deleted, and then in the dictionary tree to find the maximum value, the result, and then put two digits back.

P.S. At first my array opened to 45*10^5+10, and then he gave me the tle, and then when I put the array into 10^5+10, a, it was an array burst my time, i le a rub.

#include <stdio.h>#include<iostream>#include<string.h>#include<math.h>#include<algorithm>#include<vector>#include<string>#include<queue>#include<map>#include<stack>#include<Set>#definell Long Long#defineMAXN 100010#definePI ACOs (-1.0)//PiConstll INF =1e18;Const intlen= to;using namespacestd;structnode{intsz; intch[maxn][2]; intSUM[MAXN]; voidtrie () {sz=1; memset (CH,0,sizeof(CH)); memset (SUM,0,sizeof(sum)); }    voidAddintx) {intu=0; BOOLF;  for(inti=len;i>=0; i--) {f=x& (1<<i); if(ch[u][f]==0) ch[u][f]=sz++; U=Ch[u][f]; Sum[u]++; }    }    voidDelintx) {intu=0; BOOLF;  for(inti=len;i>=0; i--) {f=x& (1<<i); U=Ch[u][f]; Sum[u]--; }    }    intQueryintx) {intu=0; BOOLF; intCnt=0;  for(inti=len;i>=0; i--) {f=x& (1<<i); if(Sum[ch[u][!f]]) f=!F; U=Ch[u][f]; CNT=cnt| (f<<i); }        returnCNT; }}st;intT,n;intnum[1100];intMain () {scanf ("%d",&T);  while(t--) {scanf ("%d",&N);        St.trie (); intk=0;  for(intI=0; i<n;i++) {scanf ("%d",&Num[i]);        St.add (Num[i]); } ll ans=0; LL Big=0;  for(intI=0; i<n;i++)        {             for(intj=i+1; j<n;j++) {St.del (num[i]);                St.del (Num[j]); intNut=st.query (num[i]+Num[j]); Big=nut^ (num[i]+Num[j]); Ans=ans>big?Ans:big;                St.add (Num[i]);            St.add (Num[j]); }} printf ("%d\n", ans); }    return 0;}
View Code

HDU 5536 Chip Factory (dictionary tree)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.