Description

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

题意:给你一个01串,推断连续的字串[l, r]是否仅仅含同一个种字符

思路:用dp[i]记录到当前位置有多少个连续的同样字符,假设询问的区间的大小<=dp[r],那么代表就是能够的

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn = 1000005; int dp[maxn];
int n, q;
char str[maxn]; int main() {
int cas = 1;
while (scanf("%s", str) != EOF) {
int len = strlen(str);
dp[0] = 1;
for (int i = 1; i < len; i++)
if (str[i] == str[i-1])
dp[i] = dp[i-1] + 1;
else dp[i] = 1;
printf("Case %d:\n", cas++);
int l, r;
scanf("%d", &q);
while (q--) {
scanf("%d%d", &l, &r);
if (l > r)
swap(l, r);
if (r - l + 1 <= dp[r])
printf("Yes\n");
else printf("No\n");
}
}
return 0;
}

UVA - 10324 Zeros and Ones的更多相关文章

  1. 10324 - Zeros and Ones

    Problem N Zeros and Ones Input: standard input Output: standard output Time Limit: 2 seconds Memory ...

  2. UVA 12063 Zeros and Ones

    https://vjudge.net/problem/UVA-12063 题意: 统计n为二进制数中,0和1相等且值为m的倍数的数有多少个 dp[i][j][k] 前i位二进制 有j个1 值模m等于k ...

  3. UVA 12063 Zeros and Ones(三维dp)

    题意:给你n.k,问你有多少个n为二进制的数(无前导零)的0与1一样多,且是k的倍数 题解:对于每个k都计算一次dp,dp[i][j][kk][l]表示i位有j个1模k等于kk且第一位为l(0/1) ...

  4. UVA 12063 Zeros and ones 一道需要好好体会的好题

    #include<bits/stdc++.h> #include<stdio.h> #include<iostream> #include<cmath> ...

  5. 一些DP杂题

    1. [HNOI2001] 产品加工 一道简单的背包,然而我还是写了很久QAQ 时间范围是都小于5 显然考虑一维背包,dp[i]表示目前A消耗了i的最小B消耗 注意 if(b[i]) dp[j]=dp ...

  6. UVa 12063 (DP) Zeros and Ones

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

  7. UVa 12505 Searching in sqrt(n)

    传送门 一开始在vjudge上看到这题时,标的来源是CSU 1120,第八届湖南省赛D题“平方根大搜索”.今天交题时CSU突然跪了,后来查了一下看哪家OJ还挂了这道题,竟然发现这题是出自UVA的,而且 ...

  8. UVA 1252 十五 Twenty Questions

    十五 Twenty Questions Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submi ...

  9. 图-用DFS求连通块- UVa 1103和用BFS求最短路-UVa816。

    这道题目甚长, 代码也是甚长, 但是思路却不是太难.然而有好多代码实现的细节, 确是十分的巧妙. 对代码阅读能力, 代码理解能力, 代码实现能力, 代码实现技巧, DFS方法都大有裨益, 敬请有兴趣者 ...

随机推荐

  1. 自定义 Java Annotation ,读取注解值

    1. 首先是自定义注解: package cn.veji.hibernate.po; import java.lang.annotation.ElementType; import java.lang ...

  2. ORACLE索引介绍和使用

    1.什么是索引 索引是建立在表的一列或多个列上的辅助对象,目的是加快访问表中的数据: Oracle存储索引的数据结构是B*树,位图索引也是如此,只不过是叶子节点不同B*数索引: 索引由根节点.分支节点 ...

  3. swift 集成使用最新版百度地图_v2.10.2(一)

    目前在开发中使用百度地图的APP越来越多了,我在网上找的集成百度地图的例子不是很多,于是我就将我集成百度地图的过程记录了下来: 一.前提:安装CocoaPods sudo gem install co ...

  4. css--小白入门篇1

    一.引入 css用来描述html,学习css前我们先来学习html的基础标签的用法,再进入css的学习. 本教程面向小白对象,不会讲细枝末节深入的东西. 二.列表 列表有3种 2.1 无序列表 无序列 ...

  5. 洛谷——P3275 [SCOI2011]糖果

    P3275 [SCOI2011]糖果 差分约束模板题,基本思路就是$d[v]+w[v,u]<=d[u]$,$Spfa$更新方法, 有点套路的是要建立原点,即图中不存在的点来向每个点加边,但同样这 ...

  6. 洛谷——P2054 [AHOI2005]洗牌(扩展欧几里得,逆元)

    P2054 [AHOI2005]洗牌 扩展欧拉定理求逆元 $1 2 3 4 5 6$$4 1 5 2 6 3$$2 4 6 1 3 5$$1 2 3 4 5 6$ 手推一下样例,你就会发现是有规律的: ...

  7. python_ 学习笔记(hello world)

    python中的循环语句 循环语句均可以尾随一个else语句块,该块再条件为false后执行一次 如果使用break跳出则不执行. for it in [1,2,3,4]: print(it,end= ...

  8. ubuntu环境搭建DNS服务器

    1 安装bind9 apt install bind9 2 修改 named.conf.local,添加要解析的域名及对应的域名配置文件 zone "test.cn"{ type ...

  9. redis+php+mysql处理高并发实例

    一.实验环境ubuntu.php.apache或nginx.mysql二.利用Redis锁解决高并发问题,需求现在有一个接口可能会出现并发量比较大的情况,这个接口使用php写的,做的功能是接收 用户的 ...

  10. 三 , lnmp 一键包安装使用

    安装打包环境  #https://lnmp.org/----------------------------------------------------#安装wget -c http://soft ...