1. 程式人生 > >【CodeForces - 298C】Parity Game (思維,有坑)

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

題幹:

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 a

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