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

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

  2. Trailing Zeros

    Write an algorithm which computes the number of trailing zeros in n factorial. Have you met this que ...

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

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

  5. lintcode :Trailing Zeros 尾部的零

    题目: 尾部的零 设计一个算法,计算出n阶乘中尾部零的个数 样例 11! = 39916800,因此应该返回 2 挑战 O(logN)的时间复杂度 解题: 常用方法: 也许你在编程之美中看到,通过求能 ...

  6. UVa 12063 (DP) Zeros and Ones

    题意: 找出长度为n.0和1个数相等.没有前导0且为k的倍数的二进制数的个数. 分析: 这道题要用动态规划来做. 设dp(zeros, ones, mod)为有zeros个0,ones个1,除以k的余 ...

  7. Codeforces 556A Case of the Zeros and Ones(消除01)

    Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u   Description Andr ...

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

  9. Case of the Zeros and Ones

    Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Description Andrew ...

随机推荐

  1. Linux编译多个不同目录下的文件以及静态库、动态库的使用

    先看两篇博文,作为基础知识.如果对C/C++编译链接过程都了解的话,可以跳过不看. http://www.firedragonpzy.com.cn/index.php/archives/2556 ht ...

  2. 菜鸟nginx源代码剖析数据结构篇(一)动态数组ngx_array_t

    菜鸟nginx源代码剖析数据结构篇(一)动态数组ngx_array_t Author:Echo Chen(陈斌) Email:chenb19870707@gmail.com Blog:Blog.csd ...

  3. oracle至mysql该指南的数据模式()任意数据源之间的跨导应用

    为了产生的一些资源的库的释放.需要API模块迁移到mysql在,需要引导数据. 试用oracle to mysql工具.当迁移错误不说,如此大量的数据的,有了这样简陋的工具是不太可靠. 意外的发现工具 ...

  4. C++学习之路—运算符重载(二)运算符重载作为类的成员函数和友元函数

    (根据<C++程序设计>(谭浩强)整理,整理者:华科小涛,@http://www.cnblogs.com/hust-ghtao转载请注明) 对运算符重载的函数有两种处理方式:(1)把运算符 ...

  5. Servlet的学习(二)

    本篇接上一篇<Servlet的学习(一)>,讲述如何利用MyEclipse来创建web工程, 同时讲述如何在MyEclipse中配置Tomcat服务器. 在MyEclipse中,新建“We ...

  6. 棋盘问题 简单搜索DFS

    Description 在一个给定形状的棋盘(形状可能是不规则的)上面摆放棋子,棋子没有区别.要求摆放时任意的两个棋子不能放在棋盘中的同一行或者同一列,请编程求解对于给定形状和大小的棋盘,摆放k个棋子 ...

  7. Thinkphp入门 二 —空操作、空模块、模块分组、前置操作、后置操作、跨模块调用(46)

    原文:Thinkphp入门 二 -空操作.空模块.模块分组.前置操作.后置操作.跨模块调用(46) [空操作处理] 看下列图: 实际情况:我们的User控制器没有hello()这个方法 一个对象去访问 ...

  8. TVS參数具体解释及选型应用

    一.首先了解TVS管的參数,我们以littelfuse的5.0SMDJ系列为例. watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbGcybGg=/font/ ...

  9. org.apache.jasper.JasperException: java.lang.ClassCastException

    异常信息: org.apache.jasper.JasperException: java.lang.ClassCastException:org.apache.catalina.util.Defau ...

  10. Swift - 创建代理协议实现页面间参数传递和方法调用

    在开发中,经常需要用到协议代理模式.比如,进入编辑页面修改数据后,将新数据回传到主界面. 下面通过一个样例来说明协议代理模式,功能如下: 1,主页面有一个标签和一个修改按钮,点击修改按钮会跳转到编辑页 ...