题目链接

题目大意

给你一个长为n的01串,要你使得每一个01串中0和1的个数都要相等,01串中有?字符,你可以使得这个字符变为0或1,要你求是否可以满足条件。输出YES或NO

题目思路

这个题目的难度其实不大,但是最主要的问题是你要发现s[i]=s[i%k],然后就变的简单了,具体实现看代码

代码

#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<unordered_map>
#define fi first
#define se second
#define debug printf(" I am here\n");
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
const ll INF=0x3f3f3f3f3f3f3f3f;
const int maxn=3e5+5,inf=0x3f3f3f3f,mod=1e9+7;
const double eps=1e-10;
int n,k;
char s[maxn];
signed main(){
int _;
scanf("%d", &_);
while(_--){
scanf("%d%d", &n,&k);
scanf("%s",s+1);
bool flag=1;
int zer=0,one=0;
for(int i=1;i<=k;i++){
char ch='2';
for(int j=i;j<=n;j+=k){
if(s[j]=='?'){
continue;
}else {
if(ch=='2'){
ch=s[j];
}else if(ch!=s[j]){
flag=0;
break;
}
}
}
if(!flag) break;
if(ch=='1'){
one++;
}else if(ch=='0'){
zer++;
}
}
if(2*max(zer,one)>k){//不能超过一半的元素
flag=0;
}
printf(flag?"YES\n":"NO\n");
}
return 0;
}

Codeforces Round #668 C. Balanced Bitstring (Div. 2)题解(思维)的更多相关文章

  1. Codeforces Round #542 [Alex Lopashev Thanks-Round] (Div. 2) 题解

    Codeforces Round #542 [Alex Lopashev Thanks-Round] (Div. 2) 题目链接:https://codeforces.com/contest/1130 ...

  2. Codeforces Round #542 [Alex Lopashev Thanks-Round] (Div. 1) 题解

    A. Toy Train 时间限制:2 seconds 内存限制:256 megabytes 题意 有编号111~n(n≤5000)n(n\le 5000)n(n≤5000)的车站顺时针呈环排列,有m ...

  3. Codeforces Round #539&#542&#543&#545 (Div. 1) 简要题解

    Codeforces Round #539 (Div. 1) A. Sasha and a Bit of Relax description 给一个序列\(a_i\),求有多少长度为偶数的区间\([l ...

  4. Codeforces Round #668 (Div. 2)A-C题解

    A. Permutation Forgery 题目:http://codeforces.com/contest/1405/problem/A 题解:这道题初看有点吓人,一开始居然想到要用全排序,没错我 ...

  5. Codeforces Round #668 (Div. 2)【ABCD】

    比赛链接:https://codeforces.com/contest/1405 A. Permutation Forgery 题意 给出一个大小为 $n$ 的排列 $p$,定义 \begin{equ ...

  6. Codeforces Round #668 (Div. 2) D. Tree Tag 题解(博弈)

    题目链接 题目大意 给你一颗树,Alice在a点,Bob在b点,Alice最多走da步,Bob最多走db步,两人轮流走路.要你判断经过无数次追赶后,Alice是否可以追上Bob,两人进行的都是最优策略 ...

  7. Codeforces Round #668 (Div. 2) B. Array Cancellation (思维,贪心)

    题意:有一个长度为\(n\)并且所有元素和为\(0\)的序列,你可以使\(a_{i}-1\)并且\(a_{j}+1\),如果\(i<j\),那么这步操作就是免费的,否则需要花费一次操作,问最少操 ...

  8. Codeforces Round #542 [Alex Lopashev Thanks-Round] (Div. 1) C(二分+KMP)

    http://codeforces.com/contest/1129/problem/C #include<bits/stdc++.h> #define fi first #define ...

  9. Codeforces Round #542 [Alex Lopashev Thanks-Round] (Div. 2) A - D2

    A. Be Positive 链接:http://codeforces.com/contest/1130/problem/A 题意: 给一段序列,这段序列每个数都除一个d(−1e3≤d≤1e3)除完后 ...

随机推荐

  1. SpringBoot + Swagger Demo

    Swagger是什么? Swagger 是一个规范且完整的框架,用于生成.描述.调用和可视化 RESTful 风格的 Web 服务.  Swagger 的目标是对 REST API 定义一个标准且和语 ...

  2. 【django-simpleui】‘simpletags‘ is not a registered tag library报错的解决方法

    1:创建  templatetags文件夹 2:创建simpletags.py文件将内容粘贴进去,在下面 3:setting.py添加文件指定: 1 TEMPLATES = [ 2 { 3 'BACK ...

  3. MySql基础(常用)

    MySQL常用语句 1.查看当前所有数据库 show databases; 2.打开指定的库 use 库名; 3.查看当前库中的所有表 show tables; 4.查看其他库的表 show tabl ...

  4. Java学习的第三十二天

    1. 2.综合例题没太看懂 3.明天复习第十二章

  5. [LuoguP2161[ [SHOI2009]会场预约 (splay)

    题面 传送门:https://www.luogu.org/problemnew/show/P2161 Solution splay 的确有线段树/树状数组的做法,但我做的时候脑残没想到 我们可以考虑写 ...

  6. 【Postman】使用Postman实现接口数据关联

    首先下载安装Postman直接打开官网,点击下载按钮即可完成下载https://www.getpostman.com/downloads/ 栗子业务场景:用户登录医生账户,查询自己的处方列表数据:用户 ...

  7. 公钥、私钥、SSL/TLS、会话密钥、DES

    一,公钥私钥 1,公钥和私钥成对出现 2,公开的密钥叫公钥,只有自己知道的叫私钥 3,用公钥加密的数据只有对应的私钥可以解密 4,用私钥加密的数据只有对应的公钥可以解密 5,如果可以用公钥解密,则必然 ...

  8. 解决windows下Chrome78以上跨域失效问题

    1. 为什么需要解决chrome浏览器跨域的问题? 基于Hybird App的H5部分,可以直接打包进apk或者ipa包中,在开发过程中也不需要放置到临时搭建的服务器上,直接在本地打开html静态页面 ...

  9. jQuery JSONP

    同源策略 浏览器不允许跨域发送Ajax请求,如你在http://127.0.0.1:8000/下发送一个Ajax请求去获取http://127.0.0.1:9000/的资源. 如何解决这个问题?其实j ...

  10. Jenkins(9)- 汉化 Jenkins 网站

    如果想从头学起Jenkins的话,可以看看这一系列的文章哦 https://www.cnblogs.com/poloyy/category/1645399.html 下载插件 安装这两个插件,然后重启 ...