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. Web用户控件

    用户控件是个什么东西?自定义的反复重用的控件集合 注意:创建好用户控件后,必须添加到其他web页中才能显示出来,不能直接作为一个网页来显示,因此也就不能设置用户控件为“起始页”. 用户控件与ASP.N ...

  2. 原始的js代码和jquery对比

    Even a task as simple as this can be complicated without jQuery at our disposal. In plain JavaScript ...

  3. Python中的继承

    继承: 面向对象程序语言的一个重要特点是继承.继承提供了在已存在类的基础上创建新类的方法.继承的子类 拥有被继承的父类的所有方法,在此基础上,子类还可以添加自己的专有方法.继承是类的强有力的特点.一些 ...

  4. TCP/IP协议的编写《转载》

    基于HHARM9-EDU的TCP/IP(UDP)协议的实现 原文网址:http://blog.csdn.net/lhj0503/article/details/3323788 摘 要:嵌入式技术的发展 ...

  5. adb 命令使用的时候出现Error

    在使用adb 命令行的时候会出现Error 重启adb server 即可,使用管理员运行Cmd 命令窗口 adb kill-server adb start-server 如果是连接真机查看的时候再 ...

  6. HOOK自绘原理 good

    做“HOOK文件打开/保存对话框”的过程中,我首先研究了界面库的相关知识.界面库一般都是由C/C++这种中低级语言编码,这是因为在Windows下的界面库实现技术大都以直接操作控制Windows的消息 ...

  7. [概念] js的函数节流和throttle和debounce详解

    js的函数节流和throttle和debounce详解:同样是实现了一个功能,可能有的效率高,有的效率低,这种现象在高耗能的执行过程中区分就比较明显.本章节一个比较常用的提高性能的方式,通常叫做&qu ...

  8. MFC实现多风格真彩色大图标工具栏按钮

    研究zlib库,想实现一个类似winrar功能的小东东,打开winrar界面看它的工具栏比较好看于是动手想做一个,当然资源也使用的是winrar附带的.下面是截图:真彩色(32位)32*32大图标工具 ...

  9. 打开asp出现An error occurred on the server when processing the URL

    分享到:   2013-01-21 15:38   提问者采纳   方法一 以管理员身份运行CMD,将目录定位到%windir%\system32\inetsrv\,然后执行appcmd set co ...

  10. C语言中输入输出重定,freopen()妙用。

    使用的理由(范围):如果输入数据很庞大,需要一次又一次的重新输入和调试时可采用本函数. freopen ()函数: 1.格式 FILE * freopen ( const char * filenam ...