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 nextInt()函数
nextInt( int num) 能接受一个整数作为它所产生的随机整数的上限,下限为零,比如:nextInt(4)将产生0,1,2,3这4个数字中的任何一个数字,注意这里不是0-4,而是0-3..但 ...
- Apache multiple domains setup
Running several name-based web sites on a single IP address. Your server has a single IP address, an ...
- hdoj3351-stack
Problem Description I'm out of stories. For years I've been writing stories, some rather silly, just ...
- ubuntu12编译openwrt
搭建编译环境 Ubuntu x64 12.04下的命令: sudo apt-get install subversion sudo apt-get install git sudo apt-get i ...
- M - 昂贵的聘礼 - poj1062
Description 年轻的探险家来到了一个印第安部落里.在那里他和酋长的女儿相爱了,于是便向酋长去求亲.酋长要他用10000个金币作为聘礼才答应把女儿嫁给他.探险家拿不出这么多金币,便请求酋长降低 ...
- QQ群成员提取
var ids = document.querySelectorAll(".member_id"); var names = document.querySelectorAll(& ...
- IOS多线程的小总结
ios中多线程的实现方案有4种 1.pthread :一套通用的多线程API/适用于Unix\Linux\Windows等系统 (跨平台可移植/使用难度大) C语言 几乎不用 ...
- [Javascrip] Logging Timing Data to the Console
Learn to use console.time with console.timeEnd to get accurate timings of operations in javascript. ...
- C++高精度运算类bign (重载操作符)
大数据操作,有例如以下问题: 计算:456789135612326542132123+14875231656511323132 456789135612326542132123*14875231656 ...
- UML中的图
用例图.类图.包图.顺序图.协作图.状态图.活动图.构件图.部署图等 1.用例图 显示多个外部参与者以及他们与系统提供的用例之间的连接.用例是系统中的一个可以描述参与者与系统之间交互作用功能单元.用例 ...