Codeforces Round #180 (Div. 2) C. Parity Game 数学
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 数学的更多相关文章
- Codeforces Round #180 (Div. 1 + Div. 2)
A. Snow Footprints 如果只有L或者只有R,那么起点和终点都在边界上,否则在两者的边界. B. Sail 每次根据移动后的曼哈顿距离来判断是否移动. C. Parity Game 如果 ...
- 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 ...
- Codeforces Round #180 (Div. 2) B. Sail 贪心
B. Sail 题目连接: http://www.codeforces.com/contest/298/problem/B Description The polar bears are going ...
- Codeforces Round #180 (Div. 2) A. Snow Footprints 贪心
A. Snow Footprints 题目连接: http://www.codeforces.com/contest/298/problem/A Description There is a stra ...
- 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 ...
- 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/ ...
- Codeforces Round #200 (Div. 1)A. Rational Resistance 数学
A. Rational Resistance Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/343 ...
- Codeforces Round #369 (Div. 2) D. Directed Roads 数学
D. Directed Roads 题目连接: http://www.codeforces.com/contest/711/problem/D Description ZS the Coder and ...
- Codeforces Round #368 (Div. 2) C. Pythagorean Triples 数学
C. Pythagorean Triples 题目连接: http://www.codeforces.com/contest/707/problem/C Description Katya studi ...
随机推荐
- backbone-1.3.3源码解析-----------Event
第一次写,写的不对的请指正 backbone.js中的Event实现了自定义事件.自定义事件就是一个对象的键值对,key为事件名,value为一个function数组.在backbone这个对象中有一 ...
- WCF基礎
參考:http://www.cnblogs.com/MeteorSeed/archive/2012/04/24/2399455.html http://www.cnblogs.com/scy25114 ...
- MVC用户登录方法(lamda表达式)
public bool ValidateUser(account model) { using (assertEntities db = new assertEntities()) { acc ...
- ionic 相关
基本操作 $cordova platform update android@5.0.0 $ npm install -g cordova ionic $ ionic start myApp tabs ...
- Swift 脚本(运行时带参数)
#!/usr/bin/env xcrun swift import Foundation let args = Process.arguments print("Arg:\(args)&qu ...
- 企业部署Linux应用将拥有更低的整体拥有成本
企业部署Linux应用将拥有更低的整体拥有成本 使用Linux能为企业的IT解决方案降低TCO(整体拥有成本Total Cost of The Ownership)吗?在面临这个问题时,很多企 ...
- SQL Server 系统视图
SQL Server系统视图非常的多,因此不可能一个一个地写,我最近一直在想,对于数据库的系统视图应该如何学,但是看了一下目录之后,我呆了,我觉得每个写一次,可能都要花费1个星期的时间,如果对每一个返 ...
- CISCO ASA 防火墙 IOS恢复与升级
在IOS被误清除时的处理办法: 1.从tftp上的ios启动防火墙 防火墙启动后 ,按“ESC”键进入监控模式 rommon #2> ADDRESS=192.168.1.116 rommon # ...
- 【下有对策】verycd没有的资源有很多方法下载
由于国内专门从事假冒电驴官方欺骗中国人的verycd公司出品的冒牌官方电驴"阉割驴"目前已经阉割掉了搜索功能,请电驴爱好者们尽快更换正宗版电驴软件: 电骡--emule官方网站:h ...
- 删除qq历史签名
我们在设置新的个性签名的时候之前的签名会被记录,我们可以用手机qq删除这些历史签名,告别过去,做崭新的自己. 到需要删除的历史签名, 从右至左滑动屏幕