Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=5375
Encoding Rules: TMP = XOR (gr[i],gr[i-1]);
Look for a regular problem, think about it? Before and after characters and? The number of parity can be, a small trick is when the need to reduce the time to reduce the question mark in the interval of the smallest,
Then there is the problem of debugging:
The string is stored from the second bit of the array, scanf ("%s", s+1);
When using Min and Max, remember to empty before each use.
1#include <stdio.h>2 Const intMAXN =200010;3 intXOR (CharACharb) {4 intAA, BB;5AA = A-'0';6BB = B-'0';7 returnaa^BB;8 }9 intMain () {Ten CharGR[MAXN]; One intNUM[MAXN]; A int_min;intT, N; - inttmpintcnt, sum; - intLFT, RGT;intTT =0; thescanf"%d",&T); - while(t--){ -scanf"%s", gr+1); -gr[0] ='0'; +CNT =0; sum =0; N =0; _min =1000000; - while(Gr[n]! =' /') +n++; A for(inti =1; i < N; ++i) { atscanf"%d",&num[i]); - } -gr[n]='0'; -Num[n] =0; -n++; - for(inti =1; i < N; ++i) { in if(Gr[i]! ='?'){ -TMP = XOR (gr[i],gr[i-1]); to if(TMP) { +Sum + =Num[i]; - } the } * Else{ $CNT =0;Panax NotoginsengLFT = gr[i-1]; - for(; i<n;++i) { the if(Gr[i]! ='?'){ + if(Num[i] <_min) A_min =Num[i]; theSum + =Num[i]; + Break; - } $ Else{ $cnt++; -Sum + =Num[i]; - if(Num[i] <_min) the_min =Num[i]; - }Wuyi } theRGT =Gr[i]; - if((LfT! = RGT) && (cnt%2==1))|| (LfT = = RGT) && (cnt%2==0) )){ Wusum = Sum-_min; - } About_min =1000000; $ } - } -printf"Case #%d:%d\n",++tt,sum); - } A}
Hdoj 5375 Gray Code