Educational Codeforces Round 82 A. Erasing Zeroes
You are given a string ss. Each character is either 0 or 1.
You want all 1's in the string to form a contiguous subsegment. For example, if the string is 0, 1, 00111 or 01111100, then all 1's form a contiguous subsegment, and if the string is 0101, 100001 or 11111111111101, then this condition is not met.
You may erase some (possibly none) 0's from the string. What is the minimum number of 0's that you have to erase?
The first line contains one integer tt (1≤t≤1001≤t≤100) — the number of test cases.
Then tt lines follow, each representing a test case. Each line contains one string ss (1≤|s|≤1001≤|s|≤100); each character of ss is either 0 or 1.
Print tt integers, where the ii-th integer is the answer to the ii-th testcase (the minimum number of 0's that you have to erase from ss).
3
010011
0
1111000
2
0
0
大意就是问最少删除多少个给定序列里的0能让所有的1都毗连。不妨统计所有1的位置并遍历,发现如果两个1的位置下标的差大于1,则更新答案(不要忘记特判)。
#include <bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
char s[];
scanf("%s",s);
int i;
vector<int>v;
int ans=;
for(i=;i<strlen(s);i++)
{
if(s[i]=='')v.push_back(i);
}
if(v.size()==||v.size()==||strlen(s)==)
{
cout<<<<endl;
continue;
}
for(i=;i<v.size()-;i++)
{
if(v[i+]-v[i]!=)ans+=(v[i+]-v[i]-);
}
cout<<ans<<endl;
}
return ;
}
Educational Codeforces Round 82 A. Erasing Zeroes的更多相关文章
- Educational Codeforces Round 82 (Rated for Div. 2) A-E代码(暂无记录题解)
A. Erasing Zeroes (模拟) #include<bits/stdc++.h> using namespace std; typedef long long ll; ; in ...
- [CF百场计划]#3 Educational Codeforces Round 82 (Rated for Div. 2)
A. Erasing Zeroes Description You are given a string \(s\). Each character is either 0 or 1. You wan ...
- 【题解】Educational Codeforces Round 82
比较菜只有 A ~ E A.Erasing Zeroes 题目描述: 原题面 题目分析: 使得所有的 \(1\) 连续也就是所有的 \(1\) 中间的 \(0\) 全部去掉,也就是可以理解为第一个 \ ...
- Educational Codeforces Round 82 (Rated for Div. 2)
题外话 开始没看懂D题意跳了,发现F题难写又跳回来了.. 语文好差,码力好差 A 判第一个\(1\)跟最后一个\(1\)中\(0\)的个数即可 B 乘乘除除就完事了 C 用并查集判一下联通,每个联通块 ...
- Educational Codeforces Round 82 (Rated for Div. 2)E(DP,序列自动机)
#define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace std; ],t[]; int n,m; ][]; ...
- Educational Codeforces Round 82 (Rated for Div. 2)D(模拟)
从低位到高位枚举,当前位没有就去高位找到有的将其一步步拆分,当前位多余的合并到更高一位 #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h&g ...
- Educational Codeforces Round 82 C. Perfect Keyboard
Polycarp wants to assemble his own keyboard. Layouts with multiple rows are too complicated for him ...
- Educational Codeforces Round 82 B. National Project
Your company was appointed to lay new asphalt on the highway of length nn. You know that every day y ...
- [Educational Codeforces Round 16]E. Generate a String
[Educational Codeforces Round 16]E. Generate a String 试题描述 zscoder wants to generate an input file f ...
随机推荐
- DFT计算过程详解
DFT计算过程详解 平时工作中,我们在计算傅里叶变换时,通常会直接调用Matlab中的FFT函数,或者是其他编程语言中已经为我们封装好的函数,很少去探究具体的计算过程,本文以一个具体的例子,向你一步一 ...
- springboot项目入门解析
config:主要用来存储配置文件,以及其他不怎么动用的信息. controller:项目的主要控制文件 dao: 主要用来操作数据库 entit ...
- Java输入输出挂
import java.util.Comparator; import java.io.BufferedReader; import java.io.BufferedWriter; import ja ...
- linux双网卡双网关设置
https://blog.csdn.net/wangliang888888/article/details/60139499 在给客户做软件部署的时候,客户提出了一个需求,需要用到双网卡双网关,我研究 ...
- 【原】linux增加开机自启动脚本
在rc.local脚本中添加开机自启动程序
- blog主题——樱花
贮存一下,blog代码 QAQ 页脚html <!--live2d--> <script src="https://blog-static.cnblogs.com/file ...
- 【算法】dsu on tree初探
dsu on tree的本质是树上的启发式合并,它利用启发式合并的思想,可以将O(N^2)的暴力优化成O(NlogN),用于不带修改的子树信息查询. 具体如何实现呢?对于一个节点,继承它重儿子的信息, ...
- linux sftp 和scp 运用
Linux scp命令: Upload to remote :复制本地文件到远程 Part1: Scp -P port local_file remote_user@remote_ip:rem ...
- 安装docker并使用docker安装mysql
安装Docker 1. Docker 教程地址:https://www.runoob.com/docker/centos-docker.install.html 2.安装docker 命令:yum i ...
- Python实现一个桌面版的翻译工具【新手必学】
Python 用了好长一段时间了,起初是基于对爬虫的兴趣而接触到的.随着不断的深入,慢慢的转了其它语言,毕竟工作机会真的太少了.很多技能长时间不去用,就会出现遗忘,也就有了整理一下,供初学者学习和 ...