CodeForces - 556A Case of the Zeros and Ones
///////////////////////////////////////////////////////////////////////////////////////////////////////
作者: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.
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 the minimum length of the string that may remain after applying the described operations several times.
4
1100
0
5
01010
1
8
11101111
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掉了
代码:
var
s:array[..] of char;
i,j,n,k,m1,m2:longint;
begin
readln(n);
for i:= to n do
begin
read(s[i]);
if s[i]='' then inc(m1);
if s[i]='' then inc(m2);
end;
writeln(abs(m1-m2));
end.
CodeForces - 556A Case of the Zeros and Ones的更多相关文章
- Codeforces 556A Case of the Zeros and Ones(消除01)
Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Description Andr ...
- 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 ...
- 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 ...
- 找规律/贪心 Codeforces Round #310 (Div. 2) A. Case of the Zeros and Ones
题目传送门 /* 找规律/贪心:ans = n - 01匹配的总数,水 */ #include <cstdio> #include <iostream> #include &l ...
- 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 ...
- 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 ...
- 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 ...
- [Codeforces 555E]Case of Computer Network(Tarjan求边-双连通分量+树上差分)
[Codeforces 555E]Case of Computer Network(Tarjan求边-双连通分量+树上差分) 题面 给出一个无向图,以及q条有向路径.问是否存在一种给边定向的方案,使得 ...
- 【52.49%】【codeforces 556A】Case of the Zeros and Ones
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
随机推荐
- 利用原生js做数据管理平台
摘要:数据管理平台在当今社会中运用十分广泛,我们在应用过程中,要对数据进行存储,管理,以及删除查询等操作,而我们在实际设计的时候,大牛们大多用到的是JQuery,而小白对jq理解也较困难,为了让大家回 ...
- PuTsangTo
一. 跳跃与移动的优化与完善 先给上一次的内容做一次补救,也就是上一次中还留存的,由于键盘按键事件的第一次回调与后续回调之间会间隔个小半秒带来的跳跃落地后动作延迟的情况. 最终的键盘按下回调的处理代码 ...
- PHP防SQL注入攻击
PHP防SQL注入攻击 收藏 没有太多的过滤,主要是针对php和mysql的组合. 一般性的防注入,只要使用php的 addslashes 函数就可以了. 以下是一段copy来的代码: PHP代码 $ ...
- mybatis(三)
上面2章写了mybatis的基本操作,今天就写写mybatis的动态代理吧. 动态代理有4个基本原则: 1.userMapper.xml里面的namespace="cn.my.dao.Use ...
- epoll的ET和LT两种模式对比及注意事项
ET模式: 因为ET模式只有从unavailable到available才会触发,所以 1.读事件:需要使用while循环读取完,一般是读到EAGAIN,也可以读到返回值小于缓冲区大小: 如果应用层读 ...
- oracle 数据库(表)的逻辑备份与恢复
一.介绍逻辑备份是指使用工具export将数据对象的结构和数据导出到文件的过程.逻辑恢复是指当数据库对象被误操作而损坏后使用工具import利用备份的文件把数据对象导入到数据库的过程.物理备份即可在数 ...
- Poj 1032 Parliament
Parliament Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 19103 Accepted: 8101 Descr ...
- JS设计模式(一) 单例模式
命名空间 单例模式是JavaScript中最常见的一种模式,通过这种模式可以为我们提供一个命名空间,例如jQuery库的命名空间为jQuery或$.命名空间的使用是为了让代码更加整洁,在多人协作开发的 ...
- Jmeter脚本录制方法(一)——分别使用Badboy录制和Jmeter自带的代理服务器录制
Jmeter录制方式分三种,分别是:使用Badboy录制.Jmeter自带的代理服务器录制和手工录制,今天先介绍前两种录制方法. Badboy录制 Badboy是用C++开发的动态应用测试工具, 其拥 ...
- HAProxy安装文档
HAProxy安装文档 [toc][TOC] 一.环境说明 系统环境:CentOS Linux release 7.2.1511 (Core) 系统内核:3.10.0-327.el7.x86_64 软 ...