日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

發(fā)布時間:2023/12/10 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【CodeForces - 298C】Parity Game (思维,有坑) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

題干:

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),這個函數(shù)的值為0或1,分別在 串中有偶數(shù)個1,奇數(shù)個1? 時取到。

解題報告:

? 猜結論的思維題。。。模擬了一下發(fā)現(xiàn)真的可以,,。也就是看字符串中最多能造出多少個1來。,因為如果1 的數(shù)量大于等于b串中1的數(shù)量,,就一定能構造出來、、就是忘了如果1的個數(shù)為奇數(shù)的時候,,我們可以直接在后面添加一個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 ;}

?

總結

以上是生活随笔為你收集整理的【CodeForces - 298C】Parity Game (思维,有坑)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內容還不錯,歡迎將生活随笔推薦給好友。