Case of the Zeros and Ones 分类: CF 2015-07-24 11:05 15人阅读 评论(0) 收藏
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 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.
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
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) 收藏的更多相关文章
- 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 ...
- 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 ...
- iOS调用相机,相册,上传头像 分类: ios技术 2015-04-14 11:23 256人阅读 评论(0) 收藏
一.新建工程 二.拖控件,创建映射 三.在.h中加入delegate @interface ViewController : UIViewController 复制代码 四.实现按钮事件 -(IBAc ...
- Retinex系列之McCann99 Retinex 分类: 图像处理 Matlab 2014-12-03 11:27 585人阅读 评论(0) 收藏
一.McCann99 Retinex McCann99利用金字塔模型建立对图像的多分辨率描述,自顶向下逐层迭代,提高增强效率.对输入图像的长宽有 严格的限制,要求可表示成 ,且 ,. 上述限制来源于金 ...
- 百度编辑器UEditor ASP.NET示例Demo 分类: ASP.NET 2015-01-12 11:18 346人阅读 评论(0) 收藏
在百度编辑器示例代码基础上进行了修改,封装成类库,只需简单配置即可使用. 完整demo下载 版权声明:本文为博主原创文章,未经博主允许不得转载.
- ASP.NET 自定义URL重写 分类: ASP.NET 2014-10-31 16:05 175人阅读 评论(0) 收藏
一.功能说明: 可以解决类似 http://****/news 情形,Url路径支持正则匹配. 二.操作步骤: 1.增加URL重写模块: using System; using System.IO; ...
- ASP.NET 自定义URL重写 分类: ASP.NET 2014-10-31 16:05 174人阅读 评论(0) 收藏
一.功能说明: 可以解决类似 http://****/news 情形,Url路径支持正则匹配. 二.操作步骤: 1.增加URL重写模块: using System; using System.IO; ...
- 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 ...
- 二分图匹配(KM算法)n^4 分类: ACM TYPE 2014-10-04 11:36 88人阅读 评论(0) 收藏
#include <iostream> #include<cstring> #include<cstdio> #include<cmath> #incl ...
随机推荐
- c++l类
c++类和C#中定义类的方法异同之处: 1. 相同处: 1.1.都需要使用 class标识: 1.2.都包含有成员:函数,属性: 1.3.都有private public protect 标识的成员 ...
- ol,ul,dl,table标签的基本语法
ol,ul,dl,table标签的基本语法 有序列表: 无序列表: 自定义列表: <ol> <ul> < ...
- springday04-go2
练习:计算一个人的bmi指数.算法如下: 身高 单位是米 比如1.70 体重 单位是公斤 比如90 bmi指数 = 体重/身高/身高 如果bmi>24过重,否则正常.视图需要两个,一个是bmi_ ...
- EXTJS 5 开发环境搭建
WEBstrom eclipse下载: http://www.eclipse.org/downloads/ spket 下载: 安装方式: http://wangke0611.iteye.com/bl ...
- 找到多个与名为“Index”的控制器匹配的类型的解决方法!
“/”应用程序中的服务器错误. 找到多个与名为“Index”的控制器匹配的类型.如果为此请求(“{controller}/{action}/{id}”)提供服务的路由在搜索匹配此请求的控制器时没有指定 ...
- c++命名规则
命名规则根据不同公司有略微不同,这里按照google c++的编程标准1.文件名-全部用小写字母和下划线或横线组成,例如my_useful_class.ccmy-useful-class.ccmyus ...
- 夺命雷公狗---node.js---21之项目的构建在node+express+mongo的博客项目6之数据的遍历
首先还是来链接数据库,然后就查找,如下所示: /** * Created by leigood on 2016/8/31. */ var express = require('express'); v ...
- LDA-math-MCMC 和 Gibbs Sampling
http://cos.name/2013/01/lda-math-mcmc-and-gibbs-sampling/ 3.1 随机模拟 随机模拟(或者统计模拟)方法有一个很酷的别名是蒙特卡罗方法(Mon ...
- 一般处理程序 ashx中使用外部Session 出现不存在 解决方案
MXS&Vincene ─╄OvЁ &0000004 ─╄OvЁ MXS&Vincene MXS&Vincene ─╄OvЁ:今天很残酷,明天更残酷,后天很美好 ...
- 【转】Delphi利用系统环境变量获取常用系统目录
Delphi code //譬如 %WINDIR% 是表示系统目录的系统变量, 可以这样获取: var s: string; begin s := GetEnvironmentVariable('WI ...