[思路贪心]UVa12545 - Bits Equalizer

本文讨论了如何通过编程解决特定字符串匹配与替换的问题,包括预处理字符串以优化匹配过程,以及如何高效地执行替换操作。文章还提供了一个具体的代码示例,展示了如何实现这一任务。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

先把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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值