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. [应用篇]第六篇 JSTL之自定义函数标签库

      在之前的JSTL的总结中已经对函数标签库进行了一些说明,在这里我再一次重新整理一下! 自带函数标签库介绍 引入该标签库的方法为: <%@ taglib prefix="fn&quo ...

  2. C语言复习---用筛选法求100之内的素数

    #include <stdio.h> #include <stdlib.h> #include <math.h> int main() { int i, j; ] ...

  3. SpringJMS解析--使用示例

    Spring配置文件: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="h ...

  4. ActiveMQ基础教程----简单介绍与基础使用

    概述 ActiveMQ是由Apache出品的,一款最流行的,能力强劲的开源消息总线.ActiveMQ是一个完全支持JMS1.1和J2EE 1.4规范的 JMS Provider实现,它非常快速,支持多 ...

  5. Splay模板讲解及一些题目

    普通平衡树模板以及文艺平衡树模板链接. 简介 平衡二叉树(Balanced Binary Tree)具有以下性质:它是一棵空树或它的左右两个子树的高度差的绝对值不超过1,并且左右两个子树都是一棵平衡二 ...

  6. Angular 下的 directive (part 2)

    ngCloak ngCloak指令被使用在,阻止angular模板从浏览器加载的时候出现闪烁的时候.使用它可以避免闪烁问题的出现.   该指令可以应用于<body>元素,但首选使用多个ng ...

  7. springboot整合rabbitmq客户端连接报超时异常问题解决:An unexpected connection driver error occured java.net.SocketException: Socket Closed,java.util.concurrent.TimeoutException

    我用的是springboot2.0.6版本,对应的ampq也是2.0.6版本,然后启动一直报: 还有java.util.concurrent.TimeoutException, 用户授权什么的都对,很 ...

  8. JDK1.8源码hashMap

    一.概念 允许key为null,value为null:线程不安全:不保证映射的顺序:迭代 collection 视图所需的时间与 HashMap 实例的“容量”(桶的数量)及其大小(键-值映射关系数) ...

  9. malloc 函数详解

    很多学过C的人对malloc都不是很了解,知道使用malloc要加头文件,知道malloc是分配一块连续的内存,知道和free函数是一起用的.但是但是: 一部分人还是将:malloc当作系统所提供的或 ...

  10. centos7下安装配置redis3.0.4

    安装redis 1.进入redis官网(redis.io)下载redis稳定版安装包,目前稳定版本为3.0.4 2.在linux  /usr文件夹下新建redis文件夹,拷贝安装包redis-3.0. ...