Hdoj 5375 Gray Code

Source: Internet
Author: User

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

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.