C. Parity Game

题目连接:

http://www.codeforces.com/contest/298/problem/C

Description

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.

Sample Input

01011

0110

Sample Output

YES

Hint

题意

给你两个01串

然后你有两种操作,第一种操作是将第一个01串的第一个数擦去

第二个操作是将第一个01串结尾加上一个数k,k是01串中1的个数%2.

题解:

因为你存在擦去第一个数,和添加功能

很显然你可以构造出任何1的个数小于等于原1的个数+原1的个数%2的个数的字符串

因此,判断第一个数能否构成第二个数,只需要看1的个数就好了

代码

#include<bits/stdc++.h>
using namespace std; string a,b;
int main()
{
cin>>a>>b;
int sum1=0,sum2=0;
for(int i=0;i<a.size();i++)
if(a[i]=='1')sum1++;
for(int i=0;i<b.size();i++)
if(b[i]=='1')sum2++;
sum1+=sum1%2;
if(sum1>=sum2)cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}

Codeforces Round #180 (Div. 2) C. Parity Game 数学的更多相关文章

  1. Codeforces Round #180 (Div. 1 + Div. 2)

    A. Snow Footprints 如果只有L或者只有R,那么起点和终点都在边界上,否则在两者的边界. B. Sail 每次根据移动后的曼哈顿距离来判断是否移动. C. Parity Game 如果 ...

  2. Codeforces Round #180 (Div. 2) D. Fish Weight 贪心

    D. Fish Weight 题目连接: http://www.codeforces.com/contest/298/problem/D Description It is known that th ...

  3. Codeforces Round #180 (Div. 2) B. Sail 贪心

    B. Sail 题目连接: http://www.codeforces.com/contest/298/problem/B Description The polar bears are going ...

  4. Codeforces Round #180 (Div. 2) A. Snow Footprints 贪心

    A. Snow Footprints 题目连接: http://www.codeforces.com/contest/298/problem/A Description There is a stra ...

  5. Codeforces Round #188 (Div. 2) C. Perfect Pair 数学

    B. Strings of Power Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/318/p ...

  6. Codeforces Round #274 (Div. 1) B. Long Jumps 数学

    B. Long Jumps Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/480/problem/ ...

  7. Codeforces Round #200 (Div. 1)A. Rational Resistance 数学

    A. Rational Resistance Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/343 ...

  8. Codeforces Round #369 (Div. 2) D. Directed Roads 数学

    D. Directed Roads 题目连接: http://www.codeforces.com/contest/711/problem/D Description ZS the Coder and ...

  9. Codeforces Round #368 (Div. 2) C. Pythagorean Triples 数学

    C. Pythagorean Triples 题目连接: http://www.codeforces.com/contest/707/problem/C Description Katya studi ...

随机推荐

  1. 如何查看python selenium的api

    1. 打开命令行: command+R2. 输入: python -m pydoc -p 4567,然后:Enter3. 然后在浏览器中访问http://localhost:45674. 按ctrl+ ...

  2. Linux环境Weblogic10g服务部署

    1.先安装XManager: 2.进入XShell,远程连接Linux主机后,按如下操作即可打开XManager配置WebLogic部署服务: [root@server36 bin]# cd /[ro ...

  3. .Net 学习

    .Net 的微型Web框架Nancy ORM工具 Simple Data Ojbective-C 与 swift Xamarin for VisualStudio jQuery 1. 绝对的万金油,核 ...

  4. anible包模块管理

    ansible使用包管理模块 一般使用的包管理模块的RPM,和YUM 参数 必填 默认 选择 说明 Conf_file No YUM的配置文件 Disable_dbg_check No No Yes/ ...

  5. 推荐一个网站Stack Overflow

    网站URL:http://stackoverflow.com 我是怎么知道这个网站的呢?其实这个网站非常出名的,相信许多人都知道.如果你不知道,请继续阅读: 一次我在CSDN上面提问,但是想要再问多几 ...

  6. PropertyPlaceholderConfigurer加载属性配置文件:

    <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...

  7. 初识 istringstream、ostringstream、stringstream 运用

    今天编程练习时遇到了istringstream的用法,感觉很实用.后面附题目! C++的输入输出分为三种: (1)基于控制台的I/O (2)基于文件的I/O (3)基于字符串的I/O 1.头文件  # ...

  8. Failed to read artifact descriptor--maven问题总结(能力工场)

    在开发的过程中,作为新手,经常遇到Maven下载依赖的时候,"Failed to read artifact descriptor for xxx:jar"的错误 对于这种非业务相 ...

  9. Hadoop2.3+Hive0.12集群部署

    0 机器说明   IP Role 192.168.1.106 NameNode.DataNode.NodeManager.ResourceManager 192.168.1.107 Secondary ...

  10. Test log4net

    protected void Application_Start() { AreaRegistration.RegisterAllAreas(); FilterConfig.RegisterGloba ...