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 ...
随机推荐
- Canopy算法聚类
Canopy一般用在Kmeans之前的粗聚类.考虑到Kmeans在使用上必须要确定K的大小,而往往数据集预先不能确定K的值大小的,这样如果 K取的不合理会带来K均值的误差很大(也就是说K均值对噪声的抗 ...
- Swift游戏实战-跑酷熊猫 02 创建熊猫类
要点: 如何继承SKSpriteNode :子类必须调用SKSpriteNode的一个指定构造器 init(){ super.init(texture:texture,color:UIColor.wh ...
- PostgreSQL数据库postgresql.conf部分相关参数
listen_addresses:#指定数据库用来监听客户端连接的TCP/IP地址,默认是值是* ,表示数据库在启动以后将在运行数据的机器上的所有的IP地址上监听用户请求,可以写成机器的名字,也可以写 ...
- HTML调用servlet(一)
1.页面的数据表单 在使用Servlet处理用户请求之前,先准备一个页面,该页面用来提供数据表单.数据表单就是HTML中的<form>...</form>部分,当用户单击Sub ...
- Myeclipse10编写jsp时出现 Multiple annotations found at this line:
今天,老师讲完课做了一个小练习,就是编写一个jsp页面.写完后,我发现少些了点东西,我准备使用<% %>添加是发现,报错了 Multiple annotations found at th ...
- 一天弹出一次广告cookie
function setCookie(name, value, expire) { window.document.cookie = name + "=" + escape(val ...
- MyEclipse安装插件的三种方法和使用心得
本文讲解MyEclipse(MyEclipse10)的三种方法,以TestNG为例 Eclipse update site URL: http://beust.com/eclipse. 一.通过My ...
- Portal Page的呈現
先看一下在JSR168中提到的Portal page,可以了解一個Portal Page上大概有哪些element: OK...進入本次主題 PSML:PSML的全名是Portal Structure ...
- 关于 ActiveMQ 的消息模式
1.JMS Queue 执行 load balancer语义:一条消息仅能被一个 consumer(消费者) 收到.如果在 message 发送的时候没有可用的consumer,那么它将被保存一直到能 ...
- android 开发中的常见问题
Android studio 使用极光推送, 显示获取sdk版本失败 在 build.gradle(Module.app) 添加 android { sourceSets.main { ...