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 ...
随机推荐
- 函数和常用模块【day04】: 总结(十二)
- ceilometer主要组件分析
一.Agent 主要有compute agent 和central agent,还有一些其他的agent这里暂时不分析. agent初始化时会动态加载给定namespace的pollster插件,并通 ...
- Eclipse的一些常用的快捷键
写代码的时候常用的: Ctrl + 鼠标左键: 进入函数定义,变量声明: Alt + ←: 回到上次编辑的地方, 同理 Alt + → 可以移回来 Ctrl + O: 查找当前类的所有函数,变量 Ct ...
- JVM调优命令-jps
JVM Process Status Tool,显示指定系统内所有的HotSpot虚拟机进程. 命令格式 1 jps [options] [hostid] options参数-l : 输出主类全名或j ...
- Linux下sh文件运行及桌面环境双击运行sh文件
sh文件运行: 1.修改为可执行权限: chmod u+x hello.sh 2.运行 ./hello.sh 3.不使用可执行权限修改,用sh直接运行 sh ./hello.sh 桌面环境双击运行sh ...
- JavaScript继承详解(四)
在本章中,我们将分析Douglas Crockford关于JavaScript继承的一个实现 - Classical Inheritance in JavaScript. Crockford是Java ...
- 两个不能同时共存的条件orWhere查询
举例: //我的所有的积分记录 1,我分享的:2,我点击的:(两个条件不能共存) $activity_log = ActivitySharedLog::where(function ($query) ...
- HDU 1867 A + B for you again 字符匹配
解题报告:给你两个字符串,让你连接起来,没有前后顺序,要求是长度最短优先,其次是字典序最小.这题我用的是KMP,做两次匹配,分别把第一次跟第二次输入的字符串放前面,然后比较两次得到的字符窜的长度和字典 ...
- Django进阶之session
基于cookie做用户验证时:敏感信息不适合放在cookie中 session依赖cookie session原理 cookie是保存在用户浏览器端的键值对 session是保存在服务器端的键值对 s ...
- Android EditText被软键盘遮盖处理
这两天android app新增了透明栏效果,结果发现键盘弹起后会遮盖屏幕底部的EditText,没有像想象中的调整窗口大小,并滚动ScrollView,将EditText显示在键盘上方.之前也遇到过 ...