[思路贪心]UVa12545 - Bits Equalizer

来源:互联网 发布:知锦教育龙腾 编辑:程序博客网 时间:2024/06/04 19:38

先把0变1

然后把变的这一组的_0_1与对应_1_?变

#include<bits/stdc++.h>using namespace std;const int maxn = 210;char s[maxn],s0[maxn];int solve(int n){    int sum,_0_1,_1_0,_1_q,_0_q,cnt=0;    sum=_0_1=_1_0=_1_q=_0_q=cnt=0;    for(int i=0;i<n;i++){        if(s0[i]=='1'&&s[i]=='?') ++sum,++_1_q;        if(s0[i]=='0'&&s[i]=='?') ++sum,++_0_q;        if(s0[i]=='1'&&s[i]=='0') ++sum,++_1_0;        if(s0[i]=='0'&&s[i]=='1') ++sum,++_0_1;    }    int t=min(_1_0,_0_1);    cnt+=t,_0_1-=t,sum-=2*t;    t=min(_1_q,_0_1);    cnt+=2*t,_0_1-=t,sum-=2*t;    if(_0_1) return -1;    return  cnt+sum;}int main(){    int t,tt=0;    scanf("%d",&t);    while(t--){        scanf("%s%s",s,s0);        printf("Case %d: %d\n",++tt,solve((int)strlen(s0)));    }    return 0;}
find out what you passion is,what make you happy 
what you love doing
pursue with everything you have,work harder than anybody else
know that life doesn't always go as planed
we all have dreams,we all have visions,we can do with our lives
but there would be a lot of times when it doesn't  the way we want to,
and there happens everybody,but it not realy about how
what is important is how you respon to this situations,you know 
that's the persevere,so when you go through life struggles,dont 


complain,dont grumble everybody else ,stay positive,work harder than
everybody else ,put yourself the position on succeed
you are the only one.

0 0
原创粉丝点击