Educational Codeforces Round 106 (Rated for Div. 2) B. Binary Removals 思维+字符串
-
测试样例
input
5
10101011011
0000
11111
110
1100
output
YES
YES
YES
YES
NO -
Note
In the first testcase you can choose a sequence a=[1,3,6,9]. Removing the underlined letters from “10101011011” will produce a string “0011111”, which is sorted.
In the second and the third testcases the sequences are already sorted.
In the fourth testcase you can choose a sequence a=[3]. s′= “11”, which is sorted.
In the fifth testcase there is no way to choose a sequence a such that s′ is sorted. -
解题思路
这道题其实就是一道理解题,我们知道,我们不能在连续的地方删除,所以倘若存在至少2个连续的1在至少2个连续的0左边,那么这个字符串怎么删都不能保证是非递减的。 所以我们只要判断是否存在这种情况即可。 -
代码
/**
* @filename:B.cbp
* @Author : pursuit
* @Blog:unique_pursuit
* @email: 2825841950@qq.com
* @Date : 2021-03-18-23.10.03
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int maxn=1e5+5;
const int mod=1e9+7;
//
int t;
string s;
void solve(){
int len=s.size();
int index0,index1;
for(index1=0;index1<len-1;index1++){
if(s[index1]=='1'&&s[index1+1]=='1'){
break;
}
}
for(index0=len-2;index0>=0;index0--){
if(s[index0]=='0'&&s[index0+1]=='0'){
break;
}
}
if(index1<index0){
cout<<"NO"<<endl;
}
else{
cout<<"YES"<<endl;
}
}
int main(){
while(cin>>t){
while(t--){
cin>>s;
solve();
}
}
return 0;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)