P4812 D’s problem(d)From: admin
时间: 1000ms / 空间: 65536KiB / Java类名: Main

背景

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)的更多相关文章

  1. 1199 Problem B: 大小关系

    求有限集传递闭包的 Floyd Warshall 算法(矩阵实现) 其实就三重循环.zzuoj 1199 题 链接 http://acm.zzu.edu.cn:8000/problem.php?id= ...

  2. 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 ...

  3. C - NP-Hard Problem(二分图判定-染色法)

    C - NP-Hard Problem Crawling in process... Crawling failed Time Limit:2000MS     Memory Limit:262144 ...

  4. Time Consume Problem

    I joined the NodeJS online Course three weeks ago, but now I'm late about 2 weeks. I pay the codesch ...

  5. Programming Contest Problem Types

        Programming Contest Problem Types Hal Burch conducted an analysis over spring break of 1999 and ...

  6. hdu1032 Train Problem II (卡特兰数)

    题意: 给你一个数n,表示有n辆火车,编号从1到n,入站,问你有多少种出站的可能.    (题于文末) 知识点: ps:百度百科的卡特兰数讲的不错,注意看其参考的博客. 卡特兰数(Catalan):前 ...

  7. BZOJ2301: [HAOI2011]Problem b[莫比乌斯反演 容斥原理]【学习笔记】

    2301: [HAOI2011]Problem b Time Limit: 50 Sec  Memory Limit: 256 MBSubmit: 4032  Solved: 1817[Submit] ...

  8. [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 ...

  9. [LeetCode] The Skyline Problem 天际线问题

    A city's skyline is the outer contour of the silhouette formed by all the buildings in that city whe ...

随机推荐

  1. 数据结构(三)串---KMP模式匹配算法

    (一)定义 由于BF模式匹配算法的低效(有太多不必要的回溯和匹配),于是某三个前辈发表了一个模式匹配算法,可以大大避免重复遍历的情况,称之为克努特-莫里斯-普拉特算法,简称KMP算法 (二)KMP算法 ...

  2. bzoj千题计划230:bzoj3205: [Apio2013]机器人

    http://www.lydsy.com/JudgeOnline/problem.php?id=3205 历时一天,老子终于把它A了 哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈 因为不懂spfa ...

  3. 第7月第17天 rxswift swift3.0

    1.rxswift just(...) .subscribe(onNext: { }) https://realm.io/cn/news/slug-max-alexander-functional-r ...

  4. Struts2不扫描jar包中的action

    今天在做一个二开的项目,将struts打成jar包放在WEB-INF的目录下却扫描不到指定的路径,也就是http访问访问不到我们指定的action,其他代码可以正常使用,就是访问不到action.st ...

  5. jdk1.8源码Synchronized及其实现原理

    一.Synchronized的基本使用 关于Synchronized在JVM的原理(偏向锁,轻量级锁,重量级锁)可以参考 :  http://www.cnblogs.com/dennyzhangdd/ ...

  6. imperva代理拦截

    <external-traffic-monitoring-in-kern>true</external-traffic-monitoring-in-kern> 添加这段就可以开 ...

  7. 为什么要使用断路器Hystrix?

    为什么需要 Hystrix? 在微服务架构中,我们将业务拆分成一个个的服务,服务与服务之间可以相互调用(RPC).为了保证其高可用,单个服务又必须集群部署.由于网络原因或者自身的原因,服务并不能保证服 ...

  8. js array数组检测方式

    typeof var arr = [1,2,3]; console.log(typeof arr);//'object' 数组的本质是一种特殊的对象,所以返回'object'.typeof运算符只能用 ...

  9. CentOS版本区别及 Linux目录结构及其详解

    CentOS 7.0体验与之前版本的不同http://www.linuxidc.com/Linux/2014-07/104196.htm CentOS版本选择http://www.centoscn.c ...

  10. 替换openjdk的版本时遇到报错Transaction check error

    x想要使用jmap对jvm内存进行排查问题,但是默认安装的openjdk包中并不带有这个命令,需要新升级到新版本才有 而在安装新的版本时,遇到报错: :   file /usr/lib64/libns ...