A. Case of the Zeros and Ones

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 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.

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

 

Input
4 1100
Output
0
Input
5 01010
Output
1
Input
8 11101111
Output
6

Sample Output

 

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组成的字符串,每次可以任意选择相邻的两个字符且这两个字符一个为是0,一个是1(顺序无所谓)并去掉这两个位置得到一个新的字符串,然后可以对新串继续操作,直到不能继续操作为止。求这个最短的长度为多少。

分析:

观察输入输出后,发现其实就是计算0,1的个数,然后用大的减小的,输出不能配对的总个数。

代码:

 #include<cstdio>
#include<iostream>
using namespace std; const int maxn=; int main()
{
int n,i;
scanf("%d",&n);
char a[maxn];
scanf("%s",a);
int m0=,m1=;
for( i=;i<=n;i++)
{
if(a[i]=='')
m0++;
if(a[i]=='')
m1++;
}
int b=m1-m0;
int c=m0-m1;
if(m0<=m1)
printf("%d\n",b);
else
printf("%d\n",c);
return ;
}

由于我输入的是字符型,判断0,1时要带引号,这要注意。

A. Case of the Zeros and Ones----解题报告的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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 ...

  4. 找规律/贪心 Codeforces Round #310 (Div. 2) A. Case of the Zeros and Ones

    题目传送门 /* 找规律/贪心:ans = n - 01匹配的总数,水 */ #include <cstdio> #include <iostream> #include &l ...

  5. 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 ...

  6. C-C Radar Installation 解题报告

    C-C    Radar Installation   解题报告 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=86640#pr ...

  7. ACM: Just a Hook 解题报告 -线段树

    E - Just a Hook Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u   D ...

  8. Facebook Hacker Cup 2014 Qualification Round 竞赛试题 Square Detector 解题报告

    Facebook Hacker Cup 2014 Qualification Round比赛Square Detector题的解题报告.单击这里打开题目链接(国内访问需要那个,你懂的). 原题如下: ...

  9. 【百度之星2014~初赛(第二轮)解题报告】Chess

    声明 笔者近期意外的发现 笔者的个人站点http://tiankonguse.com/ 的非常多文章被其他站点转载.可是转载时未声明文章来源或參考自 http://tiankonguse.com/ 站 ...

随机推荐

  1. NOIP2010提高组] CODEVS 1069 关押罪犯(并查集)

    这道这么简单的题目还写了这么久.. 将每个会发生冲突的两人的怒气进行排序,然后从怒气大到小,将两个人放到不同监狱中.假如两人都已经被放置且在同一监狱,这就是答案. ------------------ ...

  2. monkeyrunner环境搭建

    对android世界小白白的人儿,弄个monkeyrunner环境吭哧哧的费了大半天的劲,没办法,因为实在是对这方面一窍不通,名词都是一个个百度才略懂一二,既然这么辛苦费劲的才能弄好,怎么也得记录下来 ...

  3. Oracle分区知识

    查询分区名称.表空间的SQL USER_SEGMENTS SELECT SEGMENT_NAME,PARTITION_NAME,TABLESPACE_NAME FROM USER_SEGMENTS; ...

  4. [转]关于 Swift 的一点初步看法

    本文转自:http://onevcat.com/2014/06/my-opinion-about-swift/ 感谢原作者 虽然四点半就起床去排队等入场,结果还是只能坐在了蛮后面的位置看着大屏幕参加了 ...

  5. (iOS)viewController背景透明化

    #ifdef __IPHONE_8_0 ) { [UIApplication sharedApplication].keyWindow.rootViewController.providesPrese ...

  6. 过目不忘JS正则表达式(转)

    正则表达式,有木有人像我一样,学了好几遍却还是很懵圈,学的时候老明白了,学完了忘光了.好吧,其实还是练的不够,所谓温故而知新,可以为师矣,今天就随我来复习一下这傲娇的正则表达式吧. 为啥要有正则表达式 ...

  7. perl5 第十三章 Perl的面向对象编程

    第十三章 Perl的面向对象编程 by flamephoenix 一.模块简介二.Perl中的类三.创建类四.构造函数 实例变量 五.方法六.方法的输出七.方法的调用八.重载九.析构函数十.继承十一. ...

  8. CSS3阴影 box-shadow的使用和技巧总结[转]

    text-shadow是给文本添加阴影效果,box-shadow是给元素块添加周边阴影效果.随着html5和CSS3的普及,这一特殊效果使用越来越普遍. 基本语法是{box-shadow:[inset ...

  9. File类常用方法

    File类是IO中常用的类 先介绍几个常用的方法: public boolean canRead(),public boolean canWrite() 测试当前文件是否可读可写,若是则返回true ...

  10. Android开发之旅:android架构

    本篇将站在顶级的高度——架构,来看android.我开篇就说了,这个系列适合0基础的人且我也是从0开始按照这个步骤来 学的,谈架构是不是有点螳臂挡车,自不量力呢?我觉得其实不然,如果一开始就对整个an ...