Parity Game CodeForces - 298C

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.

Example

Input

010110110

Output

YES

Input

00111110

Output

NO

Note

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

题意:

对01串存在两个操作: (1) 从串首删除一个字符 (2) 在串尾添加一个字符(当1的个数是奇数时添加1,否则添加0)

题解:

不考虑0的作用,因为每次要么添加,要么删除,那么1的个数最多是原来的数或者原来的数加一。

 1 #include<cmath>
 2 #include<cstdio>
 3 #include<string>
 4 #include<cstring>
 5 #include<iostream>
 6 #include<algorithm>
 7 using namespace std;
 8
 9 int main()
10 {   string a,b;
11     cin>>a>>b;
12     int suma=0,sumb=0;
13     for(int i=0;i<a.size();i++) if(a[i]==‘1‘) suma++;
14     for(int i=0;i<b.size();i++) if(b[i]==‘1‘) sumb++;
15     suma=suma+suma%2;
16     if(suma>=sumb) cout<<"YES"<<endl;
17     else cout<<"NO"<<endl;
18 } 
时间: 2024-08-24 11:09:54

Parity Game CodeForces - 298C的相关文章

Codeforces #180 div2 C Parity Game

// Codeforces #180 div2 C Parity Game // // 这道题的题目意思就不解释了 // // 题目有那么一点难(对于我而言),不多说啦 // // 解题思路: // // 首先如果a串和b串相等,不多说直接YES // 如果b串全是0,直接YES // 注意到a串有一个性质,1的个数不会超过本身的加1. // a有个1的上限设为x,b有个1的个数设为y,则如果x < y // 那么直接NO. // // 现在一般情况下,就是模拟啦,找到a的后缀和b的前缀一样的

Codeforces 549C The Game Of Parity(博弈)

The Game Of Parity Solution: 这个题只需要分类讨论就可以解决. 先分别统计奇数和偶数的个数. 然后判断谁走最后一步,如果走最后一步时候同时有偶数和奇数,那么走最后一步的赢.如果没有呢,就看剩下的是奇数还是偶数,是偶数不用说,是奇数看剩奇数个还是偶数个. 针对这几种情况讨论一下就可以. #include <bits/stdc++.h> using namespace std; int n, k, o, e; int main() { cin >> n &g

Codeforces Round #605 (Div. 3) E - Nearest Opposite Parity

题目链接:http://codeforces.com/contest/1272/problem/E 题意:给定n,给定n个数a[i],对每个数输出d[i]. 对于每个i,可以移动到i+a[i]和i-a[i](如果i+a[i]<=n,i-a[i]>=1) d[i]是指从i移动到任意一个j的步数,需满足条件a[i]和a[j]的奇偶性不同 不论奇偶,相连的边先放进vector邻接表中 如果i和i+a[i]奇偶性不同,那么ans[i]为1,把i放到queue队列里 同理,如果i和i-a[i]奇偶性不同

【Codeforces Global Round 1 A】Parity

[链接] 我是链接,点我呀:) [题意] 给你一个k位数b进制的进制转换. 让你求出来转成10进制之后这个数字是奇数还是偶数 [题解] 模拟一下转换的过程,加乘的时候都记得对2取余就好 [代码] import java.io.*; import java.util.*; public class Main { static int N = (int)1e5; static InputReader in; static PrintWriter out; static int b,k; static

Codeforces Round #605 (Div. 3) E - Nearest Opposite Parity (超级源点)

?? ?? ?? 题意:一个数组,i位置可以到达i +/- a[ i ] 位置(不越界情况下),问你每个位置要走到一个奇偶性相反的地点最少要走几次, 在现场,,然而我真的不会哈哈哈哈我好菜?? 主要是两点:超级源点(多源变单源)+ 反向建边(反向思维) 建立一个超级奇数点,一个超级偶数点: 超级奇数点为例,从该点出发,配合我们建立的反向边, 如果可以到达某个偶数点,求得的距离肯定是所有能到达他的奇数点中最小的(最短路中任意一条子路最短) 还有就是图里面写搜索记得开vis,,,树里面搜索可以不写,

Codeforces Round #485 (Div. 2) E. Petr and Permutations

Codeforces Round #485 (Div. 2) E. Petr and Permutations 题目连接: http://codeforces.com/contest/987/problem/E Description Petr likes to come up with problems about randomly generated data. This time problem is about random permutation. He decided to gene

Codeforces Global Round 1 (A-E题解)

Codeforces Global Round 1 题目链接:https://codeforces.com/contest/1110 A. Parity 题意: 给出{ak},b,k,判断a1*b^(k-1)+a2*b^(k-2)+...+ak*b^0的奇偶性. 题解: 暴力求模2意义下的值就好了. 代码如下: #include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 2e5+5; int

CodeForces Golbal Round 1

CodeForces Golbal Round 1 CF新的比赛呢(虽然没啥区别)!这种报名的人多的比赛涨分是真的快.... 所以就写下题解吧. A. Parity 太简单了,随便模拟一下就完了. B. Tape 显然就是先找一个长的把所有的全部覆盖,然后可以在上面丢掉\(k-1\)段间隙. 那么把两两之间的间隙长度拿出来排序就可以了. C. Meaningless Operations 如果\(a\)不等于\(2^k-1\)的形式,那么令\(S=2^k-1\),其中\(2^{k-1}<a<2

Educational Codeforces Round 75 (Rated for Div. 2) C. Minimize The Integer

链接: https://codeforces.com/contest/1251/problem/C 题意: You are given a huge integer a consisting of n digits (n is between 1 and 3?105, inclusive). It may contain leading zeros. You can swap two digits on adjacent (neighboring) positions if the swappi