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. Objective-c @property和@Synthesize

    在Objective-c中,使用@property来标识属性(一般是实例变量).在实现文件中使用@synthesize标识所声明的变量,让系统自动生成设置方法和获取方法. 也就是说@property和 ...

  2. ping的意思

    Ping是测试网络联接状况以及信息包发送和接收状况非常有用的工具,是网络测试最常用的命令.Ping向目标主机(地址)发送一个回送请求数据包,要求目标主机收到请求后给予答复,从而判断网络的响应时间和本机 ...

  3. 工具篇-TraceView

    --- layout: post title: 工具篇-TraceView  description: 让我们远离卡顿和黑屏 2015-10-09 category: blog --- ## 让我们远 ...

  4. iOS开发针对SQL语句的封装

      1.使用依赖关系 a.需要添加libsqlite3.tbd 静态库. b.需要添加第三方框架 FMBD.MJExtension. 2. SQL语句类封装名DataBaseSqlTool 类方法介绍 ...

  5. LinkNode 温度报警器视频(2016-05-15)

    文档就不发了,申请的时候说要官方首发,所以半个月后,这里就只上一个视频表表心意.

  6. CButtonST的用法详解【转】

    在想使用CButtonST的工程中加入BtnST.h.BtnST.cpp.BCMenu.h.BCMenu.cpp4个文件.2个类. 1. 在按钮上加入Icon,使Icon和文字同时显示 假设按钮ID为 ...

  7. Opencv 完美配置攻略 2014 (Win8.1 + Opencv 2.4.8 + VS 2013)下

    前面说了一些在OpenCV在VS2013下的配置的过程,下面说一下其中的个别的知识点,了解一下这样配置的一点点更细节的过程.其实配置项目属性的时候,有两种方式: 一.通过项目属性管理器配置项目属性表 ...

  8. 第三章 视图和URL配置

    在Mysite文件夹中,创建一个views.py的空文件,输入: from django.http import HttpResponse def hello(request): return Htt ...

  9. SqlServer和Oracle中一些常用的sql语句10 特殊应用

    --482, ORACLE / SQL SERVER --订购数量超过平均值的书籍 WITH Orders_Book AS ( SELECT Book_Name, SUM(Qty) Book_Qty ...

  10. 一、cocos2dx之如何优化内存使用(高级篇)

    本文由qinning199原创,转载请注明:http://www.cocos2dx.net/?p=93 一.内存优化原则 为了优化应用内存,你应该知道是什么消耗了你应用的大部分内存,答案就是Textu ...