【CodeForces - 298C】Parity Game (思维,有坑)

版权声明:欢迎学习我的博客,希望ACM的发展越来越好~ https://blog.csdn.net/qq_41289920/article/details/84791952

题干:

You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar bears get bored. They come up with a game. First Alice and Bob each writes a 01-string (strings that only contain character "0" and "1") a and b. Then you try to turn a into b using two types of operations:

  • Write parity(a) to the end of a. For example, .
  • Remove the first character of a. For example, . You cannot perform this operation if a is empty.

You can use as many operations as you want. The problem is, is it possible to turn ainto b?

The parity of a 01-string is 1 if there is an odd number of "1"s in the string, and 0 otherwise.

Input

The first line contains the string a and the second line contains the string b (1 ≤ |a|, |b| ≤ 1000). Both strings contain only the characters "0" and "1". Here |x|denotes the length of the string x.

Output

Print "YES" (without quotes) if it is possible to turn a into b, and "NO" (without quotes) otherwise.

Examples

Input

01011
0110

Output

YES

Input

0011
1110

Output

NO

Note

In the first sample, the steps are as follows: 01011 → 1011 → 011 → 0110

题目大意:

  告诉你两种操作,问你能否将A串变成B串。操作1:删除第一个字符。操作2:在字符串后面添parity(a),这个函数的值为0或1,分别在 串中有偶数个1,奇数个1  时取到。

解题报告:

  猜结论的思维题。。。模拟了一下发现真的可以,,。也就是看字符串中最多能造出多少个1来。,因为如果1 的数量大于等于b串中1的数量,,就一定能构造出来、、就是忘了如果1的个数为奇数的时候,,我们可以直接在后面添加一个1变成多一个1,

AC代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define ll long long
#define pb push_back
#define pm make_pair
#define fi first
#define se second
using namespace std;
const int MAX = 2e6 + 5;
int n,k;
char s[MAX],t[MAX];
int main()
{
	scanf("%s",s+1);
	scanf("%s",t+1);
	int cnt1=0,cnt2=0;
	for(int i = 1; i<=strlen(s+1); i++) {
		if(s[i] == '1') cnt1++;
	}
	for(int i = 1; i<=strlen(t+1); i++) {
		if(t[i] == '1') cnt2++;
	}
	if(cnt1&1) cnt1++;
	if(cnt1 >= cnt2) puts("YES");
	else puts("NO");
	return 0 ;
 }

猜你喜欢

转载自blog.csdn.net/qq_41289920/article/details/84791952