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. Ants(思维)

    Ants Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 12893   Accepted: 5637 Description ...

  2. 自己定义View----点击滑动选择字母列表

    因为项目须要,也不想使用网上的写好的控件,于是作死的自己定义了一个控件.特此记录下成功.效果例如以下: 首先须要把全部的字母绘制出来: private static String letters[] ...

  3. android 中文 api (72) —— BluetoothSocket[蓝牙]

    前言 本章内容是   android.bluetooth.BluetoothSocket,为Android蓝牙部分的章节翻译.蓝牙通讯套接字,代表了与远端设备的连接点,使用socket本地程序可以通过 ...

  4. WPF与Winform的选择

    最近公司计划对ERP系统全面升级,现有的ERP是简单的bs架构系统打算改版成cs.平时如自己写一些工具,小应用都是用winform就足够.但是界面总是很难看,据了解WPF在这一方面会强一些.因为之前对 ...

  5. [iOS]超详细Apache服务器的配置(10.10系统)

    配置目的:有一个自己专属的测试服务器 我们需要做以下事情: 1.新建一个目录,存放网页 2.修改Apache配置文件httpd.conf - 修改两个路径 - 增加一个属性 - 支持PHP脚本 3.拷 ...

  6. mysql性能调优与架构设计(一)商业需求与系统架构对性能的影响

    这里我们就拿一个看上去很简单的功能来分析一下. 需求:一个论坛帖子总量的统计附加要求:实时更新 在很多人看来,这个功能非常容易实现,不就是执行一条SELECT COUNT(*)的Query 就可以得到 ...

  7. Intellij IDEA 常用 设置 及 快捷键 (持续更新)

    Transparent native-to-ascii conversion以下设置都可以通过 设置中的搜索框 进行关键字搜索 0, 打开Project 设置 Command + ; 1, 打开Mod ...

  8. codeforces 463E . Caisa and Tree

    题目链接 给一棵树, 两种操作, 一种是将点u的权值改为y, 另一种是查询根节点到点u的路径上, gcd(v, u)>1的深度最深的点v. 修改操作不超过50次. 这个题, 暴力可以过, 但是在 ...

  9. NSData 数据转换

    NSData,数据,当我们需要把一些信息写入到文件里或发送到网络上,我们需要把这些数据转换下,变成纯粹的0.1字符流 数组转 NSData NSData *GLYtime = [NSKeyedArch ...

  10. prim模板

    ]; int n; ][]; ]; int prim(){ int i,j,mi,v; ;i<n;i++){ d[i]=map[][i]; vis[i]=; } ;i<=n;i++){ m ...