Ultraviolet A-10324 zeros and ones

Source: Internet
Author: User

Description

Given a string0'sAnd1'sUp1000000Characters long and indicesIAndJ, You are to answer a question whether all characters between positionMin (I, j)And positionMax (I, j)(Aggressive) are the same.

Input

There are multiple cases on input. The first line of each case gives a string0'sAnd1's. The next line contains a positive integerNGiving the number of queries for this case. The nextNLines contain queries, one per line. Each query is given by two non-negative integers,IAndJ. For each query, you are to printYesIf all characters in the string between positionMin (I, j)And positionMax (I, j)Are the same, andNoOtherwise.

Output

Each case on output shocould 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 shocould not be processed. the input may also with end of file. so keep check for both.

Sample Input

000001111130 54 25 90101010101010101010101010111111111111111111111111111111111111000000000000000054 425 601 362 7624 62110 0

Sample output

Case 1:NoYesYesCase 2:YesYesNoYesNoCase 3:Yes

Question: Give You A 01 string to determine whether the continuous string [L, R] contains only the same type of Characters

Idea: Use DP [I] to record the number of consecutive identical characters at the current position. If the size of the queried range is <= DP [R], it means it is OK.

#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;}



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.