Codeforces Gym 100203E Bits-equalizer Greedy

Source: Internet
Author: User

Original title Link: http://codeforces.com/gym/100203/attachments/download/1702/statements.pdf

Exercises

Considering that the exchange can be reduced one operation, then as far as possible to exchange, set question mark number is Z, above 1 is the number of 0 is X, and vice versa is Y, then the final answer is Z+min (x, y) +abs (x-y). The code is written by my teammates, I'm a cannon runner.

Code
#include <stdio.h>#include<algorithm>#include<iostream>#include<string.h>#include<queue>#include<ctime>#include<cmath>#include<Set>#include<stack>#include<map>#defineEPS 1e-10#defineMAXN 500010#defineINF 2*0x3f3f3f3fusing namespacestd;intT;Charstr1[ the], str2[ the];intMain () {//freopen ("in.in", "R", stdin); //freopen ("Out.out", "w", stdout);scanf"%d", &T);  for(intCAS =1; CAS <= T; cas++) {scanf ("%s%s", str1, str2); intLen =strlen (STR1); intx =0, y =0, z =0;  for(inti =0; i < Len; i++)if(Str1[i]! ='1') x + +;  for(inti =0; i < Len; i++)if(Str2[i]! ='1') y++; if(x < y) printf ("Case %d:%d\n", CAS,-1); Else{x= y = Z =0;  for(inti =0; i < Len; i++) {                if(Str1[i] = ='?') z++; Else if(Str1[i] = ='0'&& Str2[i] = ='1') x + +; Else if(Str1[i] = ='1'&& Str2[i] = ='0') y++; } printf ("Case %d:%d\n", CAs, z + min (x, y) + abs (Y-x)); }    }    return 0;}

Codeforces Gym 100203E Bits-equalizer Greedy

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.