P4812 D’s problem(d)
背景
NOIP春季系列课程
描述
小D是一名魔法师,它最喜欢干的事就是批判记者了。
这次记者招待会上,记者对于小D的数学很好奇。于是小D找了个方法把记者批判了一番。
它对记者抛出了这么一个问题:我有一个长为n的01序列,你能否找到一个位置x,使得1~x中的1的个数与x+1~n中的0的个数相等呢?
记者们表示这样的x可能有多个,因此记者回答了最小的满足要求的x。当不存在这样的x时,记者们回答了n+1。
现在小D忘了记者回答的是什么,因此它来求助你。
输入格式
一行一个01序列
输出格式
一个数表示答案。
输入样例
01100
输出样例
3
备注
数据范围
对于30%的数据n<=1000。
对于100%的数据n<=100000。
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
using namespace std;
char a[];
int main()
{
int m;
int tot0=,tot1=;
scanf("%s",&a);
m=strlen(a);
for(int i=;i<m;i++)
{
if(a[i]=='')tot0++;
}
for(int i=;i<m;i++)
{
if(a[i]=='')tot1++;if(a[i]=='')tot0--;
if(tot0==tot1)
{
printf("%d",i+);
return ;
}
}
printf("%d",m+);
return ;
}
P4812 D’s problem(d)的更多相关文章
- 1199 Problem B: 大小关系
求有限集传递闭包的 Floyd Warshall 算法(矩阵实现) 其实就三重循环.zzuoj 1199 题 链接 http://acm.zzu.edu.cn:8000/problem.php?id= ...
- No-args constructor for class X does not exist. Register an InstanceCreator with Gson for this type to fix this problem.
Gson解析JSON字符串时出现了下面的错误: No-args constructor for class X does not exist. Register an InstanceCreator ...
- C - NP-Hard Problem(二分图判定-染色法)
C - NP-Hard Problem Crawling in process... Crawling failed Time Limit:2000MS Memory Limit:262144 ...
- Time Consume Problem
I joined the NodeJS online Course three weeks ago, but now I'm late about 2 weeks. I pay the codesch ...
- Programming Contest Problem Types
Programming Contest Problem Types Hal Burch conducted an analysis over spring break of 1999 and ...
- hdu1032 Train Problem II (卡特兰数)
题意: 给你一个数n,表示有n辆火车,编号从1到n,入站,问你有多少种出站的可能. (题于文末) 知识点: ps:百度百科的卡特兰数讲的不错,注意看其参考的博客. 卡特兰数(Catalan):前 ...
- BZOJ2301: [HAOI2011]Problem b[莫比乌斯反演 容斥原理]【学习笔记】
2301: [HAOI2011]Problem b Time Limit: 50 Sec Memory Limit: 256 MBSubmit: 4032 Solved: 1817[Submit] ...
- [LeetCode] Water and Jug Problem 水罐问题
You are given two jugs with capacities x and y litres. There is an infinite amount of water supply a ...
- [LeetCode] The Skyline Problem 天际线问题
A city's skyline is the outer contour of the silhouette formed by all the buildings in that city whe ...
随机推荐
- [整理]zepto的初次使用
http://www.css88.com/doc/zeptojs_api/ http://chaoskeh.com/blog/some-experience-of-using-zepto.html
- 网页中创建音频、视频和Flash等多媒体:object元素
<object>元素:它主要用于定义网页中的多媒体,比如音频.视频.Java applets.PDF.ActiveX和Flash.Object标签是成对出现的,在object标签内可以使用 ...
- 使用渐进式JPEG来提升用户体验
今天才认识到原来JPEG文件有两种保存方式他们分别是Baseline JPEG(标准型)和Progressive JPEG(渐进式).两种格式有相同尺寸以及图像数据,他们的扩展名也是相同的,唯一的区别 ...
- 【NOI】2017 整数(BZOJ 4942,LOJ2302) 压位+线段树
[题目]#2302. 「NOI2017」整数 [题意]有一个整数x,一开始为0.n次操作,加上a*2^b,或询问2^k位是0或1.\(n \leq 10^6,|a| \leq 10^9,0 \leq ...
- java concurrent 中ExecutorService和CompletionService简单区别
举个例子,现在需要执行10个任务,这些任务都是有返回值,并且需要使用10个线程同时执行.一般的做法就是创建ExecutorService线程池,pool大小10,每个任务实现Callable接口,然后 ...
- 第10月第6天 lua 闭包
1. static int mytest(lua_State *L) { //获取上值 )); printf("%d\n", upv); upv += ; lua_pushinte ...
- spring如何管理mybatis(一) ----- 动态代理接口
问题来源 最近在集成spring和mybatis时遇到了很多问题,从网上查了也解决了,但是就是心里有点别扭,想看看到底怎么回事,所以跟了下源码,终于发现了其中的奥妙. 问题分析 首先我们来看看基本的配 ...
- linux笔记_day10_shell编程
1.shell编程 编程语言 静态语言:编译型语言 强类型(变量在使用前,必须事先声明) 事先转换成可执行语言 动态语言:解释型语言 弱类型(变量用时声明,拿来直接用,甚至不区分数据类型,一般默认都为 ...
- 洛谷 2257 - YY的GCD
莫比乌斯反演半模板题 很容易可以得到 \[Ans = \sum\limits_{p \in prime} \sum\limits_{d = 1}^{\min (\left\lfloor\frac{a} ...
- Cling项目demo实现Android+DLNA实现
dlna多屏互动技术在Android和ios上面应用很广,所以自己为了学习,就官方提供的远吗进行了学习. http://4thline.org/projects/cling 由于是一个maven构建的 ...