Description
Small d classmate recently in Flip chess game, this chess game chess pieces are black-and-white, he played this game he has played for a long time, he felt nothing new, so he intends to change a play. First he put these black and white pieces in a straight line, then he tested himself, he will randomly select a number of K, and then each flip a continuous k pieces, his goal is to all the pieces into white. But his time was limited, and he had the most time to flip m times. So the question is, he needs you to tell him if he can finish his final goal in this condition. Input
The first integer t is entered, representing the number of samples, followed by a sample of the T Group.
The first line of each set of samples has an integer k,m, the meaning of the title is shown (1<= k,m <= 100000). Then there is a 01 string, where 0 represents white and 1 is black. The length of this 01 string len will not exceed 100000. K <= Len. Output
For each set of samples, if the target output "YES" is complete, the output "NO". Sample Input
3
1 1
1
2 100
01
3 2
111111 Sample Output
YES
NO
YES
The nineth session of the University of Zhengzhou College of ACM Program design contest Title
Code:
/* name:10437: Small D Flip Game Copyright: __x author:long_long_ago date:17/12/15 15:49 description:http://
acm.zzu.edu.cn:8000/problem.php?id=10437 first because every 1 needs to be flipped, so for each 1 you have to flip it.
At the same time, the step number of <=m is required, so the first K's contiguous region must begin with the first 1 so that the K length starting at the first 1 is flipped once.
Record whether each position is flipped, and then for each position, as long as you know the position of his former K to flip the number of times to know his current state is not the final state.
That is, to count the prefixes of this flip number and to know.
When a position is flipped even several times it means that he did not flip, when the odd number of flips flipped the description.
Which means that if this position is 1, the sum of the number of flips of the first k is odd, which means that after the previous flip, his current state has become 0, which means he doesn't have to flip it, and if the current is even, it means that the flip in front of him has no effect on him, and he needs to flip it himself. * #include <iostream> #include <iomanip> #include <cstdio> #include <cstdlib> #include <stri ng> #include <cstring> #include <cmath> #include <map> #include <algorithm> #define N 100005 I
NT K, M;
using namespace Std;
String str;
int dir[n], f[n];
BOOL Fun () {int res = 0, sum = 0, Len = str.size ();
memset (f, 0, sizeof (f));
for (int i = 0; I +k <= len; i++) {if ((dir[i]+sum)%2) { res++;
F[i] = 1;
Sum + = F[i];
if (i-k + 1 >= 0) {sum = f[i-k+1];
(int i = len-k + 1 i < Len; i++) {if (dir[i]+sum)%2) return false;
else sum = f[i-k+1];
return res <= m;
int main () {#ifndef Online_judge freopen ("1.txt", "R", stdin); #endif int I, J, T, CNT;
BOOL Flag;
Cin >> T;
while (t--) {cnt = 0;
Flag = false;
Cin >> K >> m;
CIN >> str;
for (i = 0; i < str.size (); i++) {dir[i] = str[i]-' 0 ';
} if (Fun ()) cout << "YES" << Endl;
else cout << "NO" << Endl;
return 0;
}