CS240 project Problem 1
You cannot submit for this problem because the contest is ended. You can click "Open in Problem Set" to view this problem in normal mode.
Problem Statement
Consider an endlessly repeating sequence of keys, analogous to an infinite piano keyboard. This sequence follows a specific pattern that repeats indefinitely: wbwbwwbwbwbw. You need to determine if a continuous section of this sequence can be found which includes exactly W white keys (denoted by w) and B black keys (denoted by b).
Details
- The pattern for the sequence is:
wbwbwwbwbwbw. - Your task is to identify whether there is a substring in this infinite sequence that contains exactly W 'w' characters and B 'b' characters.
Constraints
- N: An integer such that
- W: An integer such that
- B: An integer such that
- The sum of W and B must be at least 1 (), ensuring that you are always looking for a non-empty segment.
Input
The input is given from Standard Input in the following format:
N
W1 B1
W2 B2
...
WN BN
Here, N denotes the number of queries. Each line after the first specifies a pair of integers Wi and Bi, which represent the numbers of 'w' and 'b' characters to check for in the string S respectively.
Output
For each query, if there is a contiguous substring in S that contains exactly Wi 'w' characters and Bi 'b' characters, output Yes; otherwise, output No.
F1 F2 ... FN
Sample Input 1
1
3 2
Sample Output 1
Yes
The first 15 characters of are wbwbwwbwbwbwwbw. You can take the 11-th through 15-th characters to form the string bwwbw, which is a substring consisting of three occurrences of w and two occurrences of b.
Sample Input 2
2
3 0
10 2
Sample Output 2
No No
The only string consisting of three occurrences of w and zero occurrences of b is www, which is not a substring of .
Sample Input 3
3
92 66
1 3
3 1
Sample Output 3
Yes No Yes
CS240 2024 Spring Project Problem
- Status
- Done
- Rule
- IOI
- Problem
- 4
- Start at
- 2024-5-30 17:00
- End at
- 2024-6-24 23:59
- Duration
- 607 hour(s)
- Host
- Partic.
- 99