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

问题链接:UVA10324 Zeros and Ones

问题简述

  输入01的串,有若干询问,问区间[l,r]字符是否相同。

问题分析

  计算一个统计数组cnt[],其值cnt[i]=n表示到i为止已经有n个连续相同的字符。

  有了这个数组再回答询问就简单了。

  这个问题给出的l和r与数组下标是一致的,需要注意。

程序说明:(略)

题记:(略)

参考链接:(略)

AC的C++语言程序如下:

/* UVA10324 Zeros and Ones */#include <bits/stdc++.h>using namespace std;const int N = 1000000;
char s[N + 1];
int cnt[N + 1];int main()
{int caseno = 0, n;while(~scanf("%s", s)) {cnt[0] = 1;for(int i = 1; s[i]; i++)cnt[i] = (s[i] == s[i - 1]) ? cnt[i - 1] + 1 : 1;printf("Case %d:\n", ++caseno);scanf("%d", &n);while(n--) {int l, r;scanf("%d%d", &l, &r);if(l > r)swap(l, r);printf("%s\n", (r - l + 1 <= cnt[r]) ? "Yes" : "No") ;}}return 0;
}

UVA10324 Zeros and Ones【水题】相关推荐

  1. 水题/poj 1852 Ants

    1 /* 2 PROBLEM:poj1852 3 AUTHER:Nicole 4 MEMO:水题 5 */ 6 #include<cstdio> 7 using namespace std ...

  2. HDU2673-shǎ崽(水题)

    如果不能够直接秒杀的题,就不算水题.又应证了那句话,有时候,如果在水题上卡住,那么此题对于你来说,也就不算是水题了额~~ 刚睡醒,迷迷糊糊. 题目的意思很简单,求一个最大的,再求一个最小的.几乎是什么 ...

  3. 图论刷水题记录(二)(最短路-----SPFA算法)

    继第一篇的后续,又来刷水题了,写的是SPFA算法,这个算法的复杂度比较玄学,感觉能不用就不用了,但是他的好处就是可以判断负圈. 3月26日: 1.POJ 1847 Tram 题意:在一个交通网络上有N ...

  4. 图论刷水题记录(一)(最短路-----dijkstra算法)

    最近实在不知道干些什么,感觉自己除了水题什么都不会做,算了去刷一刷图论的水题吧本来想合起来一起发,想了想太长的话以后看起来也不方便,题目所以今天晚上就先发了dij部分,由上到下由易变难. 1.POJ ...

  5. hdu 2041:超级楼梯(水题,递归)

    超级楼梯Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submissio ...

  6. HDU2568 前进【水题】

    前进 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submiss ...

  7. CF Round #426 (Div. 2) The Useless Toy 思维 水题

    题目链接: http://codeforces.com/contest/834/problem/A 题目描述: 输入起始状态和结束状态和数列长度, 判断旋转方向是顺时针逆时针还是不合理 解题思路: 长 ...

  8. NUC1312 Sum【水题+数学题】

    Sum 时间限制: 1000ms 内存限制: 65536KB 通过次数: 1总提交次数: 1 问题描述 认为自然数是从1-N.将每个数和+或-联系起来,然后计算这个表达式的值我们得到一个和S.这个问题 ...

  9. Codeforces 864 A Fair Game 水题

    题目链接: http://codeforces.com/problemset/problem/864/A 题目描述: 看不是是不是一串数中只有两种数且这两种数字的数量是相同的 解题思路: 水题, 水过 ...

最新文章

  1. the archive which is referenced by ...问题解决方案
  2. [20170412]bbed恢复修改记录(不等长).txt
  3. 构造代码块、静态代码块、构造方法的执行顺序
  4. Yoast SEO wordpress插件 + 所有扩展
  5. kindeditor图片服务器php,kindeditor 粘贴网络图片保存到服务器
  6. 谢宝友:会说话的Linux内核
  7. android 后台代码设置动画
  8. as3 primitives
  9. 按一个按钮会随机死人_有一个按钮,按下你会获得一千万,但会随机死一个人,你不用因此负责,你会按吗?...
  10. html5情人节贺卡,情人节贺卡祝福语
  11. win10系统关闭哪些服务器,win10.1系统哪些服务可以关闭掉?
  12. Laravel 5 - Trait method can has not been applied, because there are collisions with other trai
  13. DC靶机系列------6
  14. 【图书】前端工程化:体系设计与实践
  15. so链接及动态加载原理分析
  16. 智慧养老如何养老及智慧养老的发展情况
  17. 大学里机器人比赛的那些事
  18. 清明节网站变灰是如何实现的
  19. 天梯赛(cccc)总结(写于4.1号)
  20. 日本市场智能电视的主要功能

热门文章

  1. GDAL库进度信息编写示例
  2. Arcgis Javascript那些事儿(六)--arcgis js API本地环境配置
  3. 27岁后月薪低于8K,会被淘汰吗?
  4. 大学计算机相关理论,大学计算机理论基础 大学计算机基础理论题.doc
  5. 计算机网闸合同,网闸三大主流技术 -电脑资料
  6. 我的 2020 总结:跌宕起伏
  7. 详解:hive启动hiveserver2连JDBC报错:Could not open client transport with JDBC Uri 解决方案
  8. scala属性/成员变量
  9. JAVA有没有比robot更好用的_使用Java/Python提高工作效率01-Java Robot类
  10. 鸿蒙OS的指纹储存在哪里,鸿蒙OS发布以后,我们去哪里学习?