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. Mountain Road

    题意: n个车,过一条路,有不同的方向,路上不允许同时有两个方向的车,给出每个车的起始时间,方向,和经过路花费的时间,车最小间隔10个时间,求最后一个车通过路的最早的时间. 分析: dp[i][j][ ...

  2. Spring配置数据库固定代码

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" > &l ...

  3. Cocos2d-android (05) 渐变动画(颜色,淡入淡出。。。)

    淡入淡出.颜色渐变及动作重复执行 import org.cocos2d.actions.base.CCRepeatForever; import org.cocos2d.actions.interva ...

  4. 浅谈AndroidManifest.xml与R.java及各个目录的作用

    在开发Android项目中,AndroidManifest.xml与R.java是自动生成的.但是对于测试来说,非常重要.经过师父的点拨,我对AndroidManifest.xml与R.java有了更 ...

  5. 黑马程序员——Foundation中的OC结构体

    <span style="font-size:14px">------<a target="_blank" href="http:/ ...

  6. spring依赖注入原理剖析

    PropertyDefinition.java package junit.test; public class PropertyDefinition { private String name; p ...

  7. Http状态码的种类及含义

    1xx 临时响应:2xx 成功:3xx 重定向: 4xx 请求错误: 5xx 服务器错误: http://www.hostspaces.net/wenzhang-detail.php?id=198 常 ...

  8. 网络爬虫系统Heritrix的结构分析 (个人读书报告)

      摘要 随着网络时代的日新月异,人们对搜索引擎,网页的内容,大数据处理等问题有了更多的要求.如何从海量的互联网信息中选取最符合要求的信息成为了新的热点.在这种情况下,网络爬虫框架heritrix出现 ...

  9. navicat 或者workbench 无法连接127.0.0.1(61)的解决方法

    1.输入mysql -uroot 进入命令行模式, 2.输入"show variables like '%sock%';"查看sock文件所在位置 如: 3.配置客户端(以navi ...

  10. cocos2dx使用了第三方库照样移植android平台-解决iconv库的移植问题

    当我写这篇文章的时候我是怀着激动的心情的,因为我又解决了一个技术问题.你可能对题目还一知半解,这是什么意思,我之所以要写这篇文章就是要解决当我们在cocos2dx中使用了第三方库的时候,移植到andr ...