/// 
作者:stxy-ferryman
声明:本文遵循以下协议自由转载-非商用-非衍生-保持署名|Creative Commons BY-NC-ND 3.0 
查看本文更新与讨论请点击:http://www.cnblogs.com/stxy-ferryman/
链接被删请百度:stxy-ferryman
///

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

Examples
input
41100

output
0

input
501010

output
1

input
811101111

output
6

Note

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

题意:大致意思是给出一个01串,可删去01或10直到不能再删,输出最终01串的长度

思路:这是一道贪心,顺序什么的并不重要。因此本着贪到贪无可贪的原则,我们只需输出所有的0和1的个数再减一减就可以A掉了

代码:

vars:array[1..200005] of char;i,j,n,k,m1,m2:longint;
beginreadln(n);for i:=1 to n dobeginread(s[i]);if s[i]='1' then inc(m1);if s[i]='0' then inc(m2);end;writeln(abs(m1-m2));
end.

转载于:https://www.cnblogs.com/stxy-ferryman/p/7070475.html

CodeForces - 556A Case of the Zeros and Ones相关推荐

  1. [Codeforces 555E]Case of Computer Network(Tarjan求边-双连通分量+树上差分)

    [Codeforces 555E]Case of Computer Network(Tarjan求边-双连通分量+树上差分) 题面 给出一个无向图,以及q条有向路径.问是否存在一种给边定向的方案,使得 ...

  2. A. Case of the Zeros and Ones

    题目链接:http://codeforces.com/contest/556/problem/A #include <iostream> #include <cstdlib> ...

  3. CodeForces - 556C Case of Matryoshkas

    ///  作者:stxy-ferryman 声明:本文遵循以下协议自由转载-非商用-非衍生-保持署名|Creative Commons BY-NC-ND 3.0  查看本文更新与讨论请点击:http: ...

  4. CodeForces - 555A Case of Matryoshkas(思维)

    题目链接:点击查看 题目大意:类似于俄罗斯套娃,给出两个规则,每次可以选择一个规则进行操作,问最少需要多少操作才能形成1->2->...->n的局面 可以将a套入b中,当且仅当 a没 ...

  5. 【Codeforces】A2组刷题记录(50 / 50)完结

    目录 A1. Counterexample A2. Good Number A3. Dice Tower ★A4. Alyona and Numbers A5. Mountain Scenery rz ...

  6. matlab公共函数之保存YUV数据

    matlab保存图像为YUV格式的脚本函数 % function flag = saveYUVData(filename,Y,U,V,format) % input params. % filenam ...

  7. matlab期末题库,Matlab-期末考试题库(共12套卷)

    [ymin,Imin]=min(y); xmin=x(ymin);→xmin=x(Imin);%(4)找到最小函数值对应的x值 四.编程题(30分) 1.自己设计一个m函数文件,用来画出椭圆x*x/1 ...

  8. matlab 生命游戏(可调节代数,存活条件,繁殖条件)

    以前写的,主要是受到golly这个软件的启发(感觉是个很好玩的软件) 这个生命游戏可调节代数,存活条件,繁殖条件 like this 运行效果 代码: function lifeinput(arg1) ...

  9. MIMO信道的信道容量

    作者:alpswy,转载请注明出处 //受工作时间所限,本文中的仿真结果均未在博客中做出整理,如对仿真结果感兴趣,本文附带了本文中所有结果的仿真程序,请自行修改参数后使用Matlab仿真查看 假设信道 ...

最新文章

  1. 看了 100多份简历后,想给找工作的程序员几点建议
  2. 苹果电脑安装python-4. 在苹果系统上使用 Python
  3. 3DSlicer27:OpenIGTLinkIF
  4. [ An Ac a Day ^_^ ] CodeForces 468A 24 Game 构造
  5. go的错误处理(异常捕获、处理):defer+recover机制处理错误、自定义异常(自定义错误)
  6. python函数的使用方法_Python函数使用
  7. 《学习OpenCV3》第2章 OpenCV初探
  8. 【LeetCode】Python之旅 1-2
  9. 区块链软件公司:食品溯源+区块链
  10. Parquet文件格式简介
  11. 批量图片下载器(整站下载)
  12. cocoa 自动键值观察(KVO)--笔录
  13. 下载NVIDIA官方驱动教程
  14. Python文本彩色图像去污
  15. 1.bboss-bboss启动无法加载ES参数问题跟踪
  16. 数据挖掘:实用案例分析 下载_萌低龄,超实用“萌系”呈现技巧及设计案例分析...
  17. php表格合并_phpword 合并单元格的坑
  18. 创建桌面快捷方式及锁定到任务栏
  19. 突发!百度CEO李彦宏被当众泼了一瓶水
  20. LeetCode——Weekly Contest 314

热门文章

  1. php 查询datetime,急急PHP,数据库中createtime字段类型为datetime,怎样根据这个查询一段时间内的数据...
  2. package.json 中的 bin 字段作用
  3. 长尾关键词优化也要讲技巧
  4. php7和7.1,PHP7.0和7.1 部分新增特性备忘代码分享
  5. 中常用的数据结构_C语言实现常用数据结构:基本概念(第0篇
  6. c++输出的值精确到小数点后5位_C的探查之路05-基本类型
  7. ajax调用上一个ajax,关于jquery:当频繁使用ajax请求调用函数时,如何在处理下一个请求之前等待上一个ajax请求完成?...
  8. python实现火车票查询工具_Python 实现一个火车票查询的工具
  9. android隐藏状态栏
  10. (转载)linux下输入输出重定向和管道符