首页 > 其他分享 >Educational Codeforces Round 154 (Rated for Div. 2) B. Two Binary Strings

Educational Codeforces Round 154 (Rated for Div. 2) B. Two Binary Strings

时间:2023-10-16 21:58:57浏览次数:31  
标签:std Binary Educational Rated 154 字符串

给定两个长度相等的 \(01\) 字符串 \(a\) 和 \(b\) 。每个字符串都是以 \(0\) 开始以 \(1\) 结束。
在一步操作中,你可以选择任意一个字符串:

  • 选择任意两个位置 \(l, r\) 满足 \(s_l = s_r\) ,然后让 \(\forall i \in [l, r], s_i = s_l\) 。

询问经过若干次操作后能否使得 \(a = b\) 。

显然若 \(a, b\) 经过若干次操作后可以相等,则存在一个 \(x\) ,使得:

  • \(a_x = 0, a_{x + 1} = 1\)
  • \(b_x = 0, b_{x + 1} = 1\)
view
#include <bits/stdc++.h>
typedef long long ll;
void solve(){
	std::string a, b;
	std::cin >> a >> b; int n = a.length();
	a = " " + a; b = " " + b;
	for (int i = 1; i < n; i++) {
		if (a[i] == '0' && a[i + 1] == '1') {
			if (b[i] == '0' && b[i + 1] == '1') {
				std::cout << "YES\n";
				return;
			}
		}
	}
	std::cout << "NO\n";
}
int main() {
	int _ = 1; std::cin >> _;
	while (_--) {solve();}
	return 0;
}

假设没有每个字符串以 \(0\) 开始以 \(1\) 结束的条件,也可以使用分类讨论解决。

  • \(a_1 \neq b_1\) 或者 \(a_n \neq b_n\) 则不能。
  • 否则 \(a_1 = a_n\) 一定能。
  • 再否则,找 \(01\) 串或 \(10\) 串。

标签:std,Binary,Educational,Rated,154,字符串
From: https://www.cnblogs.com/zsxuan/p/17768458.html

相关文章

  • Testing Round 16 (Unrated) B. Square?
    给定一个矩形,然后切成两个矩形。尺寸分别为\(a\timesb\),\(c\timesd\)。你需要确定开始的矩形是否可能是个正方形。假设初始矩形为正方形,则两个小矩形的长边是正方形的边长。不妨让\(a\geqb,c\geqd\)。只需判断\(a=c,a=b+d\)是否成立即可。view#includ......
  • Educational Codeforces Round 91 (Rated for Div. 2) A. Three Indices
    给一个\(n\)个整数的排列\(p_1,p_2,\cdots,p_n\),需要找到三个数\(i,j,k\)满足:\(1\leqi<j<k\leqn\)\(p_i<p_j\),\(p_j<p_k\)否则回答不可能。\(key\):若存在上述\(i,j,k\),则存在\(x\)满足\(p_{x-1}<p_{x},p_{x}>p_{x+1......
  • Landsat 8 Collection 2 Tier 1 calibrated top-of-atmosphere (TOA) reflectance
    Landsat8Collection2Tier1calibratedtop-of-atmosphere(TOA)reflectance.Calibrationcoefficientsareextractedfromtheimagemetadata.See Chanderetal.(2009) fordetailsontheTOAcomputation.Landsatsceneswiththehighestavailabledataqual......
  • 了解 MySQL 数据库的三大日志(redo log、undo log、binary log)
    前言MySQL中有以下几种日志,包括:redolog(重做日志)undolog(回滚日志)binarylog(二进制日志)errorlog(错误日志)slowquerylog(慢查询日志)generallog(一般查询日志)relaylog(中继日志)事务的特性:原子性(Atomicity):事务是最小的执行单位,不允许分割。事务的原子......
  • CF1204D2 Kirk and a Binary String (hard version) 题解
    CF1204D2KirkandaBinaryString(hardversion)题解分析先来分析\(01\)串的最长不下降子序列。全是\(0\)显然是不下降的,如果中间出现一个\(1\),为了维护不下降的性质,后面就只能全是\(1\)。一句话概括一下,\(0\)后面能跟\(0,1\),\(1\)后面只能跟\(1\)。现在来分析这......
  • Binary Tree Postorder Traversal
    SourceGivenabinarytree,returnthepostordertraversalofitsnodes'values.ExampleGivenbinarytree{1,#,2,3},1\2/3return[3,2,1].ChallengeCanyoudoitwithoutrecursion?题解1-递归首先使用递归便于理解。C++-Tra......
  • Educational Codeforces Round 116 (Rated for Div. 2) A. AB Balance
    给一个长为\(n\)的字符串\(s\),只包含\(0\)\(1\)两种字符。定义\(AB(s)\)是\(s\)中出现的\(01\)子串个数,\(BA(s)\)是\(s\)中出现的\(10\)子串个数。在一步操作中,可以选择一个字符进行异或。询问最小的操作次数使得\(AB(s)=BA(s)\)。显然连续的\(11\)或连......
  • Educational Codeforces Round 96 (Rated for Div. 2) A. Number of Apartments
    有三种建筑:三室厅、五室厅、七室厅。每个房间严格有一扇窗户。现在有\(n\)扇窗户,询问完全用完这些窗户的情况下,\(3,5,7\)室厅各有多少间。输出任意一种答案,或者回答不可能。假设一定有解,显然可以选择\(mod\)任意一个数贪心,不妨选最小的\(3\)。假设答案为\(a,b,c\):......
  • Educational Codeforces Round 156 (Rated for Div. 2) A-E
    A题签到题分余1余2余0讨论 #include<bits/stdc++.h>usingnamespacestd;#definemaxn400100#defineintlonglongintread(){intans=0,f=1;charch=getchar();while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}......
  • Educational Codeforces Round 156 A-D
    A.SumofThree思路1:1.把数拆成1,2,n-32.如果(n-3)%3==0,那么拆成1,4,n-5,可证明n-3如果可被3整除,那么再左移两位一定除不尽思路2:1.如果n是奇数,那么可取一个数为2,其他两数为相邻数,如果两数其中一位被整除,那么两者往外走2.如果n为偶,那么可取一个数为1,同理上点击查看代码#inclu......