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. Delphi中运行时改变panel的位置及大小(通过wm_SysCommand来实现)

    procedure TForm1.pnl1MouseDown(Sender: TObject; Button: TMouseButton;  Shift: TShiftState; X, Y: Int ...

  2. Axure基础系列教程

     Axure rp 6.5的软件安装.汉化与注册  认识Axure的软件界面 生成网页原型的三种方法 如何关闭IE浏览器在生成原型时候的安全警告 在chrome中使用axure生成原型的问题 站点地图 ...

  3. Android 百度地图开发(二)--- 定位功能之MyLocationOverlay,PopupOverlay的使用

    转载请注明出处http://blog.csdn.net/xiaanming/article/details/11380619 这一篇文章主要讲解的是百度地图的定位功能,然后还有MyLocationOv ...

  4. Linux下select函数的使用

    一.Select 函数详细介绍 Select在Socket编程中还是比较重要的,可是对于初学Socket的人来说都不太爱用Select写程序,他们只是习惯写诸如connect. accept.recv ...

  5. (5/9)*(f-32)与5*(f-32)/9

    今天在Linux下用c语言写个小程序玩玩,主要就是根据华氏温度计算摄氏温度.公式是:摄氏度=(5/9)*(华氏度-32) 代码很简单~ #include<stdio.h> main() { ...

  6. mysql-5.6.13在windows平台下的安装、使用(图解)

    本文同步至:http://www.waylau.com/mysql-5-6-13-windows-platform-installation-use-graphic/ 一. 首先电脑要具备.Net F ...

  7. Microsoft office PPT 2007 保存时速度慢(整理自网上)

    问题描述: XP sp3上运行PPT2007,当需要保存文件时,发现竟然需要近1分钟才能保存完毕,其间可能会出现“瘟都死沙漏”来提示你正在保存. 这简直慢到过分慢到无法容忍,一开始以为是ppt文件过大 ...

  8. 基本HTML5文件结构

    作者 : Dolphin 原文地址:http://blog.csdn.net/qingdujun/article/details/28129039 基本HTML5文件结构: <!--<!D ...

  9. 在Java中使用MD5和BASE64

    MD5: 在上一篇<Servlet的学习之Session(5)>中,为了能使获取的所有随机数都能有相同的位数,我们采用MD5获取随机数的消息摘要(或称数据指纹.数据摘要等等). MD5可以 ...

  10. Scanner类及正则表达式

    import java.util.Scanner; public class ScannerToString { public static void main(String[] args) { Sc ...