Codeforces 556A:Case of the Zeros and Ones
1 second
256 megabytes
standard input
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 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
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:
.
Codeforces喜欢把一些很简单的答案隐藏在复杂的问题之下,因为0和1总会相邻啊。。。所以这题就是求0和1的差的绝对值。。。
代码:
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#pragma warning(disable:4996)
using namespace std; string tes;
int n;
int n0;
int n1; int main()
{
//freopen("i.txt", "r", stdin);
//freopen("o.txt", "w", stdout); int i; n0 = 0;
n1 = 0; cin >> n;
cin >> tes;
for (i = 0; i < n; i++)
{
if (tes[i] == '0')
n0++;
else
n1++;
}
cout << abs(n0 - n1) << endl;
//system("pause");
return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
Codeforces 556A:Case of the Zeros and Ones的更多相关文章
- 【52.49%】【codeforces 556A】Case of the Zeros and Ones
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 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 ...
- 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 ...
- 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 ...
- android switch语句报错:case expressions must be constant expressions
今天无意中碰见了 case expressions must be constant expressions 的问题 写了一个 switch(item.getItemId()) { case R. ...
- SQL Server -- 回忆笔记(四):case函数,索引,子查询,分页查询,视图,存储过程
SQL Server知识点回忆篇(四):case函数,索引,子查询,分页查询,视图,存储过程 1. CASE函数(相当于C#中的Switch) then '未成年人' else '成年人' end f ...
- SQL进阶1:case表达式的用法示例
一:case表达式的用法 1.SQL中的case表达式的作用是用来对"某个变量"进行某种转化,通常在select字句中使用,举个例子: 不能看出,case表达式很像我们的if el ...
随机推荐
- 设计模式课程 设计模式精讲 14-2 组合模式coding
1 代码演练 1.1 代码演练1(组合模式1) 1.2 代码演练2(组合模式1之完善) 1 代码演练 1.1 代码演练1(组合模式1) 需求: 打印出木木网的课程结构, 我们用一个组建类作为接口,课程 ...
- 深度解析Java可变参数类型以及与数组的区别
注意:可变参数类型是在jdk1.5版本的新特性,数组类型是jdk1.0就有了. 这篇文章主要介绍了Java方法的可变参数类型,通过实例对Java中的可变参数类型进行了较为深入的分析,需要的朋友可以参考 ...
- 无线冲方案 WPC Qi v1.2.4 update
参考: 1. Qi标准v1.2.4最新版 2. Qi Baseline Power Profile (BPP) and Extended Power Profile (EPP) Wireless Ch ...
- js 动画提示数据有变化
let groupZiArray = $.....; for (let i = 1; i < groupZiArray.length; i++) { let $groupZi = $(group ...
- layer open type值类型
参考:http://layer.layui.com/api.html layer提供了5种层类型: 0:信息框,默认 1:页面层 2:iframe层 3:加载层 4:tips层
- 小笔记----about JC
JC project JAVA,Mysql. 页面用velocity template engine render的html/css Apache Velocity template engine ...
- VirtualBox安装Debian
1.下载Debian的dvd1,按照http://www.jb51.net/os/85858.html网上教程安装Debian 1.1.我创建了20G的虚拟磁盘,分区的时候我分了3个区,2G交换空间, ...
- 085、Java数组之实现排序
01.代码如下: package TIANPAN; /** * 此处为文档注释 * * @author 田攀 微信382477247 */ public class TestDemo { public ...
- 自动PC端显示 手机端隐藏CSS代码判断实现
实现场景描述: 有些内容部署在PC端但是有不适合在手机端显示(比如盒子过大,遮挡内容)或者手机端显示毫无意义等.我们可以使用下面的代码来实现:电脑端显示,手机端隐藏 实现方法: CSS控制判断 @me ...
- 通过注册码破解IntelliJ IDEA
把激活码填入下面的地方即可.如果不知道在哪里,那么就选菜单栏里的help再选Register就会弹出下面的界面 激活码网址里面有 lookdiv.com 里面的钥匙就是lookdiv.com