CF1566C MAX-MEX Cut

题目传送门

CF1566C MAX-MEX Cut

思路

如果这一列是 01 01 01 10 10 10,那么肯定是直接合贡献更大,答案直接加 2 2 2

如果这一列是 00 00 00 或者 11 11 11,那么看看是否可以和前一列合并。如果可以,则答案加 2 2 2。如果不可以,可以打上标记,等后面的,看看可不可以合并。

代码

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
inline int read(){
    int x=0,f=1;char c=getchar();
    for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
    for(;isdigit(c);c=getchar()) x=(x<<3)+(x<<1)+c-'0';
    return x*f;
}
inline void write(int x){
    if(x<0) putchar('-'),x=-x;
    if(x>9) write(x/10);
    putchar(x%10+'0');
}
string s1,s2;
int t,n,x,ans;
bool f1,f2;
void solve(){
	n=read(),cin>>s1>>s2;
	ans=0,x=-1;
	for(int i=0;i<n;i++){
		f1=((s1[i]=='0')|(s2[i]=='0')),f2=((s1[i]=='1')|(s2[i]=='1'));
		if(f1&&f2) x=2,ans+=x;
		else{
			if(!f1){
				if(x==1) ans++,x=-1;
				else x=0;
			}else{
				ans++;
				if(x==0) ans++,x=-1;
				else x=1;
			}
		}
	}
	cout<<ans<<endl;
}
signed main(){
	t=read();
	while(t--) solve();
	return 0;
}

提交记录

  • 7
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值