Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

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
程序分析:此题的意思就是找出0比1多多少个,或者是1比0多多少个。也就是0和1的差。所以我需要分别统计出0和1的个数就好,然后在做差运算即可。
程序代码:
#include<iostream>

using namespace std;
char a[];
int main()
{
int n,l,b=,t,c=;
cin>>n;
for(l=;l<n;l++)
{ cin>>a[l]; if(a[l]=='')
c++;
else b++;
}
if(b>c)
t=b-c;
else t=c-b;
cout<<t<<endl;
return ;
}

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

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

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

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

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

  7. Codeforces 556A Case of the Zeros and Ones(消除01)

    Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u   Description Andr ...

  8. CodeForces - 556A Case of the Zeros and Ones

    //////////////////////////////////////////////////////////////////////////////////////////////////// ...

  9. 【52.49%】【codeforces 556A】Case of the Zeros and Ones

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

随机推荐

  1. 解决shell脚本中 echo 怎么写入换行到文件

    測试环境:ubuntu12.04 LTS版本号 echo >> file.txt就可以, 这样的方法对于脚本开头是bash和sh效果都一样, 而echo -e >> file. ...

  2. JQuery的JSTree使用

    这是一个树形菜单的展示.其功能及其强大,几乎可以提供你对树结构的各种要求.下面,对其简述.    首先,感谢 Ivan Bozhanov利用JQuery对该组件的开发.同时还要感谢我的技术总监Mr. ...

  3. BZOJ 1677: [Usaco2005 Jan]Sumsets 求和( dp )

    完全背包.. --------------------------------------------------------------------------------------- #incl ...

  4. js取一维数组最大值,最小值

    最近项目中遇到了,处理数组数据问题:     var newStrs=[1,2,3,4];               alert(Math.min.apply(null,newStrs));  // ...

  5. Mac Yosemite下Android Studio环境问题集合

    1. java not found 在mac Yosemite下,因jre升级到1.8,导致Android Studio无法启动.报错:"JAVA not found". 解决方法 ...

  6. 字符通向字节流的桥梁---- OutputStreamWriter

    OutputStream out = System.out; OutputStreamWriter osw = new OutputStreamWriter(out); BufferedWriter ...

  7. AnyEvent::HTTP 介绍

    AnyEvent::HTTP - simple but non-blocking HTTP/HTTPS client 一个简单的非堵塞的 HTTP/HTTPS 客户端: use AnyEvent::H ...

  8. POJ-1003&1004

    这两题比较简单,就不做分析了,描述下题目,就上代码吧. [题目描述] 1003,其实就是求这个方程的最小n:1/2 + 1/3 + 1/4 + ... + 1/(n + 1) >= c: 100 ...

  9. BZOJ 2440 完全平方数

    2440: [中山市选2011]完全平方数 Time Limit: 10 Sec  Memory Limit: 128 MB Submit: 966  Solved: 457 [Submit][Sta ...

  10. Swift入门Hello World! Swift.

    苹果公司推出新的开发语言Swift,随着关于趋势,外观和OC什么是不一样的地方. 前提条件:已安装Xcode6-Beta(这个过程是不表) 1.打开Xcode6-Beta,第二选择Create a n ...