10324 - Zeros and Ones
Problem N
Zeros and Ones
Input: standard input
Output: standard output
Time Limit: 2 seconds
Memory Limit: 32 MB
Given a string of 0's and 1's up to 1000000 characters long and indices i and j, you are to answer a question whether all characters between position min(i,j) and position max(i,j) (inclusive) are the same.
Input
There are multiple cases on input. The first line of each case gives a string of 0's and 1's. The next line contains a positive integer n giving the number of queries for this case. The next n lines contain queries, one per line. Each query is given by two non-negative integers, i and j. For each query, you are to print Yes if all characters in the string between position min(i,j) and position max(i,j) are the same, and No otherwise.
Output
Each case on output should start with a heading as in the sample below. The input ends with an empty string that is a line containing only the new line character, this string should not be processed. The input may also with end of file. So keep check for both.
Sample Input
0000011111
3
0 5
4 2
5 9
01010101010101010101010101111111111111111111111111111111111110000000000000000
5
4 4
25 60
1 3
62 76
24 62
1
1
0 0
Sample Output
Case 1:
No
Yes
Yes
Case 2:
Yes
Yes
No
Yes
No
Case 3:
Yes
#include<stdio.h>
#include<string.h>
#define max(a,b) a>b?a:b
#define min(a,b) a<b?a:b
char a[1000005];
int check(int x,int y)
{
int z;
for(z=x;z<=y;z++)
if(a[x]!=a[z])
return 0;
return 1;
}
int main()
{
int n,i,j,k,count=1;
while(scanf("%s",a)!=EOF)
{
printf("Case %d:\n",count++);
scanf("%d",&n);
for(k=0;k<n;k++)
{
scanf("%d%d",&i,&j);
if(check(min(i,j),max(i,j)))
puts("Yes");
else
puts("No");
}
}
return 0;
}
10324 - Zeros and Ones的更多相关文章
- UVA - 10324 Zeros and Ones
Description Given a string of 0's and 1's up to 1000000 characters long and indices i and j, you are ...
- Trailing Zeros
Write an algorithm which computes the number of trailing zeros in n factorial. Have you met this que ...
- Case of the Zeros and Ones 分类: CF 2015-07-24 11:05 15人阅读 评论(0) 收藏
A. Case of the Zeros and Ones time limit per test 1 second memory limit per test 256 megabytes input ...
- Codeforces Round #310 (Div. 2) A. Case of the Zeros and Ones 水题
A. Case of the Zeros and Ones Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/con ...
- lintcode :Trailing Zeros 尾部的零
题目: 尾部的零 设计一个算法,计算出n阶乘中尾部零的个数 样例 11! = 39916800,因此应该返回 2 挑战 O(logN)的时间复杂度 解题: 常用方法: 也许你在编程之美中看到,通过求能 ...
- UVa 12063 (DP) Zeros and Ones
题意: 找出长度为n.0和1个数相等.没有前导0且为k的倍数的二进制数的个数. 分析: 这道题要用动态规划来做. 设dp(zeros, ones, mod)为有zeros个0,ones个1,除以k的余 ...
- Codeforces 556A Case of the Zeros and Ones(消除01)
Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Description Andr ...
- A. Case of the Zeros and Ones----解题报告
A. Case of the Zeros and Ones Description Andrewid the Android is a galaxy-famous detective. In his ...
- Case of the Zeros and Ones
Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Description Andrew ...
随机推荐
- delphi中左右翻转窗体(修改EXStyle)
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Form ...
- Mongodb 上传图片
mongdb 上传图片: [root@hy-mrz01 ~]# mongofiles put -u "pics" -p "jh7yxx" --host 127. ...
- struts2 <s:iterator/>怎样取得循环的索引
<s:iterator value="list" id="user" status="L"> <s:property va ...
- 为什么要用BitSet
BitSet适用于一类型boolean判断,Java的BitSet在这类型判断中非常高效. 举例说明:在判断前2000万数字中素数个数的程序中,如果使用最基本的素数判断代码: package com; ...
- poj 2777 Count Color(线段树区区+染色问题)
题目链接: poj 2777 Count Color 题目大意: 给出一块长度为n的板,区间范围[1,n],和m种染料 k次操作,C a b c 把区间[a,b]涂为c色,P a b 查 ...
- Tomcat详细用法学习(二)
本篇接上一篇<Tomcat详细用法学习(一)>,主要讲解服务器的虚拟目录映射的几种方式. 先来看几个概念: web应用的概念:一个web应用包含了许多我们做好的web资源,里面或许包括了多 ...
- linux:sed高级命令之n、N(转)
sed的语法格式: sed [option] {sed-command} {input-file} sed在正常情况下,将处理的行读入模式空间(pattern space),脚本中的“sed-comm ...
- CentOS6.4 安装Mysql
虽说,新版的数据包可能会带上一些新特性,但是数据库对我而言,还是稳定版优先.因为新特性不一定我会用到.. 下载安装: yum list | grep mysql 因为是准备搞开发用的,所以只要安装my ...
- Linux教程:如何在Linux下进行C++开发?
Linux是一类Unix计算机操作系统的统称,Linux操作系统的内核的名字也是“Linux”, 在Linux下进行C++开发,需要注意许多问题,比如:减少不必要的编辑动作,减少编辑的时间. Wind ...
- 关于yaf的控制器命名,一个纠结的问题(续)
以下方案缺少loader相关的步骤,明天补上!!! 前面写过一篇<关于yaf的控制器命名,一个纠结的问题>.没想到yaf群里面也有跟我遇到一样问题的人,分享下解决办法. 写完那篇博文后,我 ...