Codeforces 1221F Game With String thinking title

The meaning of problems: there are two people playing the game, the rules of the game as follows: there is a string of length n, and X are constituted by a string, Alice can select a contiguous them into X, Bob may select consecutive. to b. put them into X. Title guarantee a> b, Alice the upper hand, and asked who in the case of the two sides do not turn on the water to win?

Ideas: notes that a> b this critical condition, the condition is a breach of this problem. Since a> b, we can be constituted by a section divided into four categories: 1: b is smaller than the length of the section, no one could fill this interval, without regard. 2: b is smaller than a length greater than or equal section, such section may be filled only b. 3: not less than a length less than the interval 2 * b. Both sides of this section can be filled, but this range can not become the type of zone 2. 4: not less than the length of the interval 2 * b. This step may change the type of section 2 of section. First, we found that if the interval type 2 exist, Alice must not win, because Bob can fill this interval. And, if the interval is greater than one type 4, Alice shall lose, because Bob simply select a type of interval 4, a variable of type section 2, to win the Bob. Then the remaining two cases: 1: no type of zone 4. On the outcome of this situation and the number of the relevant sections of type 3. 2: Only one type of zone 4, when Alice is also possible to remedy it. We just need to enumerate how to fill Alice, and then determine whether this filling can to win.

Code:


				if(get(len) == 4) {
					re = len;
				}
				len = 0;
			}
		}
		cnt[get(len)]++;
		if(get(len) == 4) {
			re = len;
		}
		if(cnt[2] > 0) {
			printf("No\n");
			continue;
		}
		if(cnt[4] > 1) {
			printf("No\n");
			continue;
		}
		if(cnt[4] == 1) {
			bool flag = 0;
			for (int i = 0; i <= re - a; i++) {
				int len1 = i, len2 = re - (i + a), tmp = 0;
				if(get(len1) == 2 || get(len1) == 4 || get(len2) == 2 || get(len2) == 4) continue;
				if(get(len1) == 3) tmp++;
				if(get(len2) == 3) tmp++;
				if((cnt[3] + tmp) % 2 == 0) {
					printf("Yes\n");
					flag = 1;
					break;
				}
			}
			if(flag == 0) {
				printf("No\n");
			}
		} else {
			if(cnt[3] % 2 == 1) {
				printf("Yes\n");
			} else {
				printf("No\n");
			}
		}
	}
}

  

Guess you like

Origin www.cnblogs.com/pkgunboat/p/11573227.html