• UVA


    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:
    ", 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
    ");
    			else printf("No
    ");
    		}
    	}
    	return 0;
    }



  • 相关阅读:
    Server Tomcat v8.5 Server at localhost failed to start.
    使用bootstrap中的bootstrapValidator,验证ckeditor富文本框不为空
    百度WebUploader上传图片,图片回显编辑,查看
    百度WebUploader上传图片
    做webapp静态页面的一些积累
    ztree插件的使用
    highcharts曲线图
    ajax的表单提交,与传送数据
    一条数据中需要遍历多条数据,页面遍历方法
    在页面中使用拼接字符串的方式显示动态加载的数据
  • 原文地址:https://www.cnblogs.com/wzzkaifa/p/7107328.html
Copyright © 2020-2023  润新知