A. Case of the Zeros and Ones
来源:互联网 发布:linux hexdump源码 编辑:程序博客网 时间:2024/05/16 00:29
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 adjacent positions 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.
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 the minimum length of the string that may remain after applying the described operations several times.
41100
0
501010
1
811101111
6
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的个数,然后进行删除即可,由于0和1总有相邻的情况出现,所以不需要判断0和1出现的位置。
#include<stdio.h>int main(){int i,sum=0,j=0,k=0,n;char a[200001];scanf("%d",&n);scanf("%s",a);for(i=0;i<n;i++){if(a[i]=='0'){j++;}else{k++;}}if(j>k){j=k;}sum=n-(2*j);printf("%d\n",sum);return 0;}
- A. Case of the Zeros and Ones
- A. Case of the Zeros and Ones
- CodeForces 556A Case of the Zeros and Ones
- CodeForces-556A Case of the Zeros and Ones
- codeforces 556A Case of the Zeros and Ones
- Codeforces 556A:Case of the Zeros and Ones
- coderforce A. Case of the Zeros and Ones
- CodeForces 556A Case of the Zeros and Ones
- 【52.49%】【codeforces 556A】Case of the Zeros and Ones
- Case of the Zeros and Ones
- Case of the Zeros and Ones
- Case of the Zeros and Ones
- Codeforces 556A Case of the Zeros and Ones 消除01串
- A. Case of the Zeros and Ones(Codeforces Round #310 (Div. 2) 栈)
- CF#310-A-Case of the Zeros and Ones-链表模拟
- CodeForces NO.556A Case of the Zeros and Ones(stack,110101010)
- Codeforces Round #310 (Div. 2)-A. Case of the Zeros and Ones
- the Zeros and Ones
- 重要通知:博客迁移至 ZYaller
- dubbox消费端和服务端
- Java操作PDF之iText超入门
- Windows API timeGetTime Intro
- 欢迎使用CSDN-markdown编辑器
- A. Case of the Zeros and Ones
- UITableView优化
- NGUI 小总结
- JSP的运行原理及本质
- Android-->巧用XListView,打造万能的下拉刷新控件
- 开源监控软件ganglia安装手册
- Solr4.7从文件创建索引
- 开发者交流群资料链接备份
- 删除软链接目录文件