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)