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