A. Case of the Zeros and Ones
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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 twoadjacent 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 lengthn - 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 test(s)
Input
4
1100
Output
0
Input
5
01010
Output
1
Input
8
11101111
Output
6
CF的一道水题
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <algorithm> using namespace std; const int MAX = 200200; char str[MAX]; int main()
{
int n;
scanf("%d",&n);
scanf("%s",str);
int a=0,b=0;
for(int i=0;i<n;i++)
{
if(str[i]=='0')
{
a++;
}
else
{
b++;
}
}
int sum=abs(a-b);
printf("%d\n",sum);
return 0; }

版权声明:本文为博主原创文章,未经博主允许不得转载。

Case of the Zeros and Ones 分类: CF 2015-07-24 11:05 15人阅读 评论(0) 收藏的更多相关文章

  1. Power Strings 分类: POJ 串 2015-07-31 19:05 8人阅读 评论(0) 收藏

    Time Limit:3000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit Status Practice POJ ...

  2. Segment Tree with Lazy 分类: ACM TYPE 2014-08-29 11:28 134人阅读 评论(0) 收藏

    #include<stdio.h> #include<string.h> #include<algorithm> using namespace std; stru ...

  3. iOS调用相机,相册,上传头像 分类: ios技术 2015-04-14 11:23 256人阅读 评论(0) 收藏

    一.新建工程 二.拖控件,创建映射 三.在.h中加入delegate @interface ViewController : UIViewController 复制代码 四.实现按钮事件 -(IBAc ...

  4. Retinex系列之McCann99 Retinex 分类: 图像处理 Matlab 2014-12-03 11:27 585人阅读 评论(0) 收藏

    一.McCann99 Retinex McCann99利用金字塔模型建立对图像的多分辨率描述,自顶向下逐层迭代,提高增强效率.对输入图像的长宽有 严格的限制,要求可表示成 ,且 ,. 上述限制来源于金 ...

  5. 百度编辑器UEditor ASP.NET示例Demo 分类: ASP.NET 2015-01-12 11:18 346人阅读 评论(0) 收藏

    在百度编辑器示例代码基础上进行了修改,封装成类库,只需简单配置即可使用. 完整demo下载 版权声明:本文为博主原创文章,未经博主允许不得转载.

  6. ASP.NET 自定义URL重写 分类: ASP.NET 2014-10-31 16:05 175人阅读 评论(0) 收藏

    一.功能说明: 可以解决类似 http://****/news 情形,Url路径支持正则匹配. 二.操作步骤: 1.增加URL重写模块: using System; using System.IO; ...

  7. ASP.NET 自定义URL重写 分类: ASP.NET 2014-10-31 16:05 174人阅读 评论(0) 收藏

    一.功能说明: 可以解决类似 http://****/news 情形,Url路径支持正则匹配. 二.操作步骤: 1.增加URL重写模块: using System; using System.IO; ...

  8. Fibonacci Again 分类: HDU 2015-06-26 11:05 13人阅读 评论(0) 收藏

    Fibonacci Again Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tot ...

  9. 二分图匹配(KM算法)n^4 分类: ACM TYPE 2014-10-04 11:36 88人阅读 评论(0) 收藏

    #include <iostream> #include<cstring> #include<cstdio> #include<cmath> #incl ...

随机推荐

  1. Mybatis-Plugin插件学习使用方法

    以下教程仅供学习使用,针对于IntelliJ Idea 15中的Mybatis Plugin插件. 作者博客中的教程:http://myoss.github.io/2016/MyBatis-Plugi ...

  2. Summary: Merge Sort of Array && 求逆序对

    常用算法(后面有inplace版本): package ArrayMergeSort; import java.util.Arrays; public class Solution { public ...

  3. android开发之如何使TabHost的TabWidget位于屏幕下方

    更改TabHost里的第一个LinearLayout为RelativeLayout.并在TabWidget中添加android:layout_alignParentBottom="true& ...

  4. C++之路进阶——bzoj1823(满汉全席)

    F.A.Qs Home Discuss ProblemSet Status Ranklist Contest ModifyUser  hyxzc Logout 捐赠本站 Notice:由于本OJ建立在 ...

  5. sql 中各种锁随记

    一. 为什么要引入锁    多个用户同时对数据库的并发操作时会带来以下数据不一致的问题:    丢失更新  A,B两个用户读同一数据并进行修改,其中一个用户的修改结果破坏了另一个修改的结果,比如订票系 ...

  6. R12月末关帐的异常检查和处理

    在R12版本中月末关帐时经常会出现关不了的情况,而系统的异常报表的信息太过简单且不完全.结合项目本身发生的情况,做了以下的总结,希望能对公司其他R12项目有所启示. R12月度关帐的要点: 检查SLA ...

  7. 夺命雷公狗---DEDECMS----19dedecms栏目列表页的完成

    我们的栏目页表页的模版如果不清楚叫什么名,可以通过: 这里很清楚的记录着,我们来看下他: 他长得和我们以前做首页时候是不是很像呢?其实就是一样的,我们改下即可,如下所示: {dede:channel ...

  8. linux中使用软链接时出现 too many levels of symbolic links

    刚开始使用的源文件的路径是相对路径,所以导致标题中的这种错误. 只要用绝对路径表示源文件就好了.如果用相对路径的话,实际相对的是目标文件所在的路径,而在创建链接文件时用的路径是相对于当前的路径.

  9. django templates学习使用记录

    可以在基本模板中多插入几个black来适应不同的布局

  10. JQuery ajax方法及参数

    ©屋主原创,版权归 todayeeee 所有!如需转载,必须在页面明显位置给出原文链接!商业用途请 联系我!   $.ajax({ type: 'GET',    // 这是请求的方式 可以是GET方 ...