Codeforces 556A Case of the Zeros and Ones(消除01)
Description
Andrewid the Android is a galaxy-famous detective. In his free time he likes to think about strings containing zeros and ones.
Once he thought about a string of length n consisting of zeroes and ones. Consider the following operation: we choose any two adjacentpositions in the string, and if one them contains 0, and the other contains 1, then we are allowed to remove these two digits from the string, obtaining a string of length n - 2 as a result.
Now Andreid thinks about what is the minimum length of the string that can remain after applying the described operation several times (possibly, zero)? Help him to calculate this number.
Input
First line of the input contains a single integer n (1 ≤ n ≤ 2·105), the length of the string that Andreid has.
The second line contains the string of length n consisting only from zeros and ones.
Output
Output the minimum length of the string that may remain after applying the described operations several times.
Sample Input
4
1100
0
5
01010
1
8
11101111
6
Hint
In the first sample test it is possible to change the string like the following: .
In the second sample test it is possible to change the string like the following: .
In the third sample test it is possible to change the string like the following: .
题解:看字符串中的0和1的个数,相减
#include<cstdio>
#include<cstring>
int n,p,q;
char a[];
int main()
{
scanf("%d",&n);
scanf("%s",&a);
q=,p=;
for(int i=; i<n; i++)
{
if(a[i]=='')
p++;
if(a[i]=='')
q++;
}
if(p>=q)
printf("%d",p-q);
else
printf("%d",q-p);
return ;
}
Codeforces 556A Case of the Zeros and Ones(消除01)的更多相关文章
- CodeForces - 556A Case of the Zeros and Ones
//////////////////////////////////////////////////////////////////////////////////////////////////// ...
- Codeforces 556A:Case of the Zeros and Ones
A. Case of the Zeros and Ones time limit per test 1 second memory limit per test 256 megabytes input ...
- Codeforces Round #310 (Div. 2) A. Case of the Zeros and Ones 水题
A. Case of the Zeros and Ones Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/con ...
- 找规律/贪心 Codeforces Round #310 (Div. 2) A. Case of the Zeros and Ones
题目传送门 /* 找规律/贪心:ans = n - 01匹配的总数,水 */ #include <cstdio> #include <iostream> #include &l ...
- Codeforces 556 A Case of the Zeros and Ones
A. Case of the Zeros and Ones time limit per test 1 second memory limit per test 256 megabytes input ...
- Case of the Zeros and Ones 分类: CF 2015-07-24 11:05 15人阅读 评论(0) 收藏
A. Case of the Zeros and Ones time limit per test 1 second memory limit per test 256 megabytes input ...
- A. Case of the Zeros and Ones----解题报告
A. Case of the Zeros and Ones Description Andrewid the Android is a galaxy-famous detective. In his ...
- [Codeforces 555E]Case of Computer Network(Tarjan求边-双连通分量+树上差分)
[Codeforces 555E]Case of Computer Network(Tarjan求边-双连通分量+树上差分) 题面 给出一个无向图,以及q条有向路径.问是否存在一种给边定向的方案,使得 ...
- CodeCraft-19 and Codeforces Round #537 (Div. 2) D 多重排列 + 反向01背包 + 离线处理
https://codeforces.com/contest/1111/problem/D 多重排列 + 反向01背包 题意: 给你一个字符串(n<=1e5,n为偶数),有q个询问,每次询问两个 ...
随机推荐
- [JAVA关键字] synchronized
synchronized, Example: public synchronized void XXX() {} 参考 http://wenku.baidu.com/link?url=ecb1Zivf ...
- SRM 390(1-250pt)
DIV1 250pt 题意:给定整数n和k,问最少需要多少个n连接在一起形成的新整数t,使得t是k的倍数.如果不能形成倍数,输出-1.k <= 10^5,n <= 10^9. 解法:不断增 ...
- J - Invitation Cards
题目大意:邀请卡 在电视的时代,没有多少人会去剧院观看演出.古老的喜剧演员 Malidinesia知道这个事实.他们想传播戏剧尤其是古老的戏剧,他们在邀请卡上打印必要的信息和一些节目,一些学生被雇佣过 ...
- 高性能Java Web 页面静态化技术(原创)
package com.yancms.util; import java.io.*; import org.apache.commons.httpclient.*; import org.apache ...
- 关于这两天研究Java打印pdf方法的记录
这两天在研究Java调用打印机打印PDF文件的方法,学到了不少东西,特别来记录一下. 关于Java打印网上最多的而且也是Java正统的打印方法就是使用PrintService,一套比較标准的打印代码例 ...
- win7 32/64bit VS2010 OpenCV 2.4.9 环境配置
作者 : 卿笃军 因为近期人脸识别须要用到OpenCV,让我開始了OpenCV学习. OpenCV 2.4.9下载地址:http://sourceforge.net/projects/opencvli ...
- mac eclipse配置 tomcat
mac由于各种软件不兼容,某些软件对于开发来说很苦恼,tomcat这个东西一直不知道怎么弄,项目都开了好几天了,一直用在虚拟机上用windows系统,但是用虚拟机明显感觉到电池待机时间更短了,所以就研 ...
- codevs1226倒水问题(Bfs)
/* 首先建立模型 可以看成是三个水杯 第三个无穷大 (这里看成是201足够了) 最少步数 想到Bfs 维护队列里的状态:要有个步数 还要有v :此时刻三个杯子有多少水 然后倒水:因为没有刻度 所以有 ...
- python运算符使用规律
#conding=utf-8 #优先级使用规律#1.一般情况下是左右结合print 4+6+5*6+6 #2.出现赋值的时候一般是右结合a=8+91print a #优先级记忆口诀'''函数寻址下标1 ...
- 查看Oracle数据库被锁住的表,删除锁表的进程
锁表处理及查询 查看Oracle数据库被锁住的表,删除锁表的进程 1.查看被锁住的表 SELECT dob.object_name table_name, lo.locked_mode, lo. ...