Codeforces Round #668 C. Balanced Bitstring (Div. 2)题解(思维)
题目链接
题目大意
给你一个长为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)题解(思维)的更多相关文章
- Codeforces Round #542 [Alex Lopashev Thanks-Round] (Div. 2) 题解
Codeforces Round #542 [Alex Lopashev Thanks-Round] (Div. 2) 题目链接:https://codeforces.com/contest/1130 ...
- 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 ...
- Codeforces Round #539Ȟȟȡ (Div. 1) 简要题解
Codeforces Round #539 (Div. 1) A. Sasha and a Bit of Relax description 给一个序列\(a_i\),求有多少长度为偶数的区间\([l ...
- Codeforces Round #668 (Div. 2)A-C题解
A. Permutation Forgery 题目:http://codeforces.com/contest/1405/problem/A 题解:这道题初看有点吓人,一开始居然想到要用全排序,没错我 ...
- Codeforces Round #668 (Div. 2)【ABCD】
比赛链接:https://codeforces.com/contest/1405 A. Permutation Forgery 题意 给出一个大小为 $n$ 的排列 $p$,定义 \begin{equ ...
- Codeforces Round #668 (Div. 2) D. Tree Tag 题解(博弈)
题目链接 题目大意 给你一颗树,Alice在a点,Bob在b点,Alice最多走da步,Bob最多走db步,两人轮流走路.要你判断经过无数次追赶后,Alice是否可以追上Bob,两人进行的都是最优策略 ...
- Codeforces Round #668 (Div. 2) B. Array Cancellation (思维,贪心)
题意:有一个长度为\(n\)并且所有元素和为\(0\)的序列,你可以使\(a_{i}-1\)并且\(a_{j}+1\),如果\(i<j\),那么这步操作就是免费的,否则需要花费一次操作,问最少操 ...
- 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 ...
- 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)除完后 ...
随机推荐
- linux系统软件启动sh脚本
在系统维护中,编写脚本会帮助运维提高效率,现记录一个通用的软件启动脚本.脚本内容如下: #!/bin/bash # 软件启动程序包名称 APP_NAME=datadog-4.2.0.jar # 软件名 ...
- 想用Nginx代理一切?行!
Nginx能代理一切吗? 是的,Nginx可以作为一个优秀的http网关,但nginx能代理SSH2,MySQL,Oracle的连接吗?也算行吧,nginx有stream-module,专门处理TCP ...
- mysql 快速清除数据表数据
mysql> truncate tables; 例如: mysql> truncate email_managements;
- numpy数组运算
一.四则运算 (以此为例) 1.加法 2.减法 3.乘法 4.除法 5.幂运算 二.比较运算 (以此为例) 1.< > 2.>= <= 3.== != ...
- js 自适应手机电脑 轮播图
自己写了一个javascript的可循环轮播图,支持手机滑动,不过代码着实小白,全局变量,函数调用满天飞,研究别的代码规范好的轮播图插件,表示看得懂但是写不出.. HTML: <div id=& ...
- 为什么要谨慎使用Arrays.asList、ArrayList的subList?
1. 使用Arrays.asList的注意事项 1.1 可能会踩的坑 先来看下Arrays.asList的使用: List<Integer> statusList = Arrays.asL ...
- PriorityQueue原理分析——基于源码
在业务场景中,处理一个任务队列,可能需要依照某种优先级顺序,这时,Java中的PriorityQueue(优先队列)便可以派上用场.优先队列的原理与堆排序密不可分,可以参考我之前的一篇博客: 堆排序总 ...
- Shell脚本常用命令整理
该笔记主要整理了一些常见的脚本操作命令,大致如下(持续补充中): 1. while.for循环 1. while.for循环 #!/bin/bash # while循环 v_start_date=${ ...
- Vuex原理详解
一.Vuex是什么 Vuex是专门为Vuejs应用程序设计的状态管理工具.它采用集中式存储管理应用的所有组件的状态,并以相应的规则保证状态以一种可预测的方式发生改变.它集中于MVC模式中的Model层 ...
- linux服务器远程网络开机(wake on lan)
通过网络可以远程开关机,某些时候比较方便管理机器 检查服务器是否支持远程网络开机 [root@lab5101 ~]# ethtool eth0 Settings for eth0: Supported ...