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. BZOJ 1266: [AHOI2006]上学路线route(最短路+最小割)

    第一问最短路.第二问,先把最短路的图建出来(边(u,v)满足d[s->u]+d[v->t]+d(u,v)==最短路径长度,就在图中,可以从源点和汇点分别跑一次最短路得到每个点到源点和汇点的 ...

  2. 制作一个vagrant的win7 box

    准备: 1.win7镜像文件 2.vagrant安装文件 3.virtual box安装文件 步骤: 1.先在本机上安装virtualbox和vagrant,本机为win7,安装虚机也为win7 2. ...

  3. RFID电子标签的二次注塑封装

    生活当中,RFID电子标签具有明显的优势,随着RFID电子标签成本的降低.读写距离的提高.标签存储容量增大及处理时间缩短的发展趋势,R F I D电子标签的应用将会越来越广泛. RFID电子标签的应用 ...

  4. 如何修改Protel99SE原理图的标题栏

    本文主要讲述了如何修改Protel99SE原理图中的标题栏内容,使用者可以根据需要修改. 标题栏的格式: 1.添加模板:(1)菜单栏Design\Template\Set Template File ...

  5. C语言数组内存初始化

    内存初始化当然有必然,但是不用memset,直接这样写就可以了:char* szRemoteFile = new char[MAX_LENGTH](); http://blog.csdn.net/pa ...

  6. 在GridView中实现全选反选的例子

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="GridView控件.asp ...

  7. 用C#开发较完整的Windows任务管理器

    原文 用C#开发较完整的Windows任务管理器 这个代码没有什么技术含量,仅仅使用 WMI 和 API 实现了 Windows 任务管理器的部分功能. 但代码里面封装了一个 SystemInfo 的 ...

  8. cython教程

    .写测试代码: zhouhh@zhouhh-home:~$ vi test.pyx [python] view plaincopy def sayhello(char* str): if str == ...

  9. mysql 假设存在id则设数据自添加1 ,不存在则加入。java月份计算比較

    </pre><pre name="code" class="sql">INSERT INTO invite_rejectlog_num ...

  10. nodejs hello world (调用文件执行没反应)

    今天学习了node.js ,来看一下hello world 的写法. 1. 首先安装node.js的驱动文件.http://nodejs.org/ 2. a:安装好node之后,在CMD窗口输入nod ...