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 ...
随机推荐
- Nested Loops(嵌套循环)
先扫描驱动表的(外表),外表的每一行驱动内表,然后匹配,所以nest loops不是主要依赖于内表有多少行,而是非常依赖于驱动表到底有多少行参与nested loops,因为驱动表(或者准确的说是驱动 ...
- 「MYSQL」MYSQL中的int(11)到底代表什么意思?
一.前言 在工作中经常要与mysql打交道,但是对mysql的各个字段类型一直都是一知半解,因此写本文总结记录一番. 二.简介 对于int类型的一些基础知识其实上图已经说的很明白了,在这里想讨论下常用 ...
- BFS搜索算法应用_Codevs 1004 四子连棋
#define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <algorithm> #include <cs ...
- .NET面试题系列(七)IIS
应用程序池的集成模式和经典模式的区别 应用程序池模式会影响服务器处理托管代码请求的方式. 如果托管应用程序在采用集成模式的应用程序池中运行,服务器将使用 IIS 和 ASP.NET 的集成请求处理管道 ...
- TTPRequest 提示#import <libxml/HTMLparser.h>找不到 的解决方法
本文永久地址为http://www.cnblogs.com/ChenYilong/p/3984251.html ,转载请注明出处. ASIHTTPRequest 或者AFNetwork提示的#impo ...
- android MeasureSpec的三个测量模式
1.MeasureSpec含义 其实可以去看MeasureSpec的文档,里面对MeasureSpec的作用介绍得很清楚.MeasureSpec封装了父布局传递给子布局的布局要求,每个MeasureS ...
- XSS小游戏通关Writeup
源码下载:https://files.cnblogs.com/files/nul1/xss%E7%BB%83%E4%B9%A0%E5%B0%8F%E6%B8%B8%E6%88%8F.zip 我也没啥可 ...
- Gitlab的安装汉化及问题解决
Gitlab的安装汉化及问题解决(2017/12/14目前版本为10.2.4) 一.前言 Gitlab需要安装的包太TM多了,源码安装能愁死个人,一直出错,后来发现几行命令就装的真是遇到的新大陆一样. ...
- WPF使用DataGridComboBoxColumn完成绑定
在使用DataGrid的时候,有时候需要使某些列为ComboBox,这时自然想到使用DataGridComboBoxColumn,但是如果使用的是ItemsSource数据绑定后台的对象,就会发现,这 ...
- maven:多个镜像配置
<mirrors> <mirror> <id>nexus-aliyun</id> <mirrorOf>nexus-aliyun</mi ...