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

题干:

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),这个函数的值为0或1,分别在 串中有偶数个1,奇数个1  时取到。

解题报告:

  猜结论的思维题。。。模拟了一下发现真的可以,,。也就是看字符串中最多能造出多少个1来。,因为如果1 的数量大于等于b串中1的数量,,就一定能构造出来、、就是忘了如果1的个数为奇数的时候,,我们可以直接在后面添加一个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 ;}

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/441078.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

java中能构成循环的语句_《编程导论(Java)#183;3.2.4 循环语句》

本文全然复制《编程导论(Java)3.2.4 循环语句》的内容。除【】中的说明文字。请阅读和比較其它编程教材。我知道。假设我是一个刚開始学习的人&#xff0c;《编程导论(Java)》非常不适合自学。建议同学们阅读时&#xff0c;一定选择一本其它的书同一时候看&#xff0c;或上网。…

*【CodeForces - 1088 ABC】套题比赛,A水题B模拟C构造D交互

A. Input The only line contains the integer xx (1≤x≤100)(1≤x≤100). Output You should output two integers aa and bb, satisfying the given conditions, separated by a space. If no pair of integers satisfy the conditions above, print "-1" (wit…

算法讲解 -- 区间dp经典模型与优化(石子归并)

石子合并问题是最经典的DP问题。首先它有如下3种题型&#xff1a; PPT讲解&#xff1a;点击打开链接 (1)有N堆石子&#xff0c;现要将石子有序的合并成一堆&#xff0c;规定如下&#xff1a;每次只能移动任意的2堆石子合并&#xff0c;合并花费为新合成的一堆石子的数量。求将…

cpu影响matlab仿真速度吗,Proteus仿真速度很慢的分析

类型&#xff1a;行业软件大小&#xff1a;1.1M语言&#xff1a;中文 评分&#xff1a;6.5标签&#xff1a;立即下载这篇文章是我的个人实践经验&#xff1a;很多朋友在做Proteus硬件仿真的时候可能都碰上了仿真速度慢的问题&#xff0c;在点击了开始仿真之后&#xff0c;CPU过…

mysql 7天自动拒单功能,mysql查询最近7天的数据,没有数据自动补0

select DATE( createtime) date , createtime, count(1) as count from order表 where DATEDIFF( now(), createtime)<7group by date ;12 月九号没有;给他在关联一张日期的表;--生成从今天开始完整的7天日期DECLARE LastSevenDaytable(day date)DECLARE StartDaydate …

基于维纳滤波的语音增强算法 matlab,基于维纳滤波语音增强算法的改进实现

通过对维纳滤波的介绍,实现了基本维纳滤波效果;利用两级维纳滤波和两级滤波器组滤波方法实现了语音增强,达到了良好的效果。维普资讯 http://doc.docsou.com文章编号&#xff1a;0 2 8 8 (o 7 0 - 0 4 0 10—6 4 2 o )1 0 4 - 3基于维纳滤波语音增强算法的改进实现白文雅&#…

php7 获取文件类型,太简单了!PHP获取文件扩展名的7中方法

PHP中获取文件扩展名的方法第一种&#xff1a;$file x.y.z.png;echo substr(strrchr($file, .), 1);解析&#xff1a;strrchr($file, .)strrchr() 函数查找字符串在另一个字符串中最后一次出现的位置&#xff0c;并返回从该位置到字符串结尾的所有字符第二种&#xff1a;$file…

【EOJ Monthly 2018.12 - A,B,C】套题训练,部分题解

A. 题干&#xff1a; A. 仰望星空 单测试点时限: 2.0 秒 内存限制: 512 MB 你就这样静坐在草地上&#xff0c;离我稍远的地方。 我用眼角瞅着你&#xff0c;你什么话也别说。 语言是误会的根源。 但是&#xff0c;每天&#xff0c;你可以坐得离我近一些…… 你和她一起仰头…

php百度搜索框代码,基于jquery的仿百度搜索框效果代码_jquery

先看看整个的效果图&#xff1a;图一&#xff1a;图二&#xff1a;图三&#xff1a;图四&#xff1a;大概的效果图就这样&#xff0c;接下来直接看源码页面&#xff1a;CSS&#xff1a;.autoSearchText{border:solid 1px #CFCFCF;height:20px;color:Gray;}.menu_v{margin:0;pad…

matlab大作业题题单,2011MATLAB大作业-题目-

(1)求解线性规划问题&#xff1a;minZ 4x1 x2 7x3s.t.x1 x2 x3 53x1 x2 x3 4x1 x2 4x3 7x1,x2 0问各xi分别取何值时&#xff0c;Z有何极小值。(2)编写一个函数&#xff0c;使其能够产生如下的分段函数&#xff1a;0.5x&#xff0c;x 2f(x) 1.5 0.25x&#xff0c;2 x 6&#xff…

php webshell编写,php webshell学习

一、环境kali 192.168.43.177开户apache /etc/init.d/apache2 start/var/www/html/目录下编辑php代码hackbarhttps://github.com/Mr-xn/hackbar2.1.3二、php基础输出函数:echo - 可以输出一个或多个字符串print - 只允许输出一个字符串&#xff0c;返回值总为 1提示&#xff1a…

【CodeForces - 27E】Number With The Given Amount Of Divisors (数论,数学,反素数)

题干&#xff1a; Given the number n, find the smallest positive integer which has exactly n divisors. It is guaranteed that for the given n the answer will not exceed 1018. Input The first line of the input contains integer n (1 ≤ n ≤ 1000). Outp…

*【UVA - 10382】Watering Grass(贪心,区间覆盖问题,思维)

题干&#xff1a; 题目大意&#xff1a; 有一块草坪&#xff0c;长为l&#xff0c;宽为w&#xff0c;在它的水平中心线上有n个位置可以安装喷水装置&#xff0c;各个位置上的喷水装置的覆盖范围为以它们自己的半径ri为圆。求出最少需要的喷水装置个数&#xff0c;如果无论如何…

oracle如何把字符集改回默认,更改oracle字符集

在安装oracle时&#xff0c;选了默认字符集是utf8&#xff0c;后来发现与plsql developer工具联合使用时&#xff0c;会出现各种乱码问题。再加上我的项目也是gbk的&#xff0c;因此&#xff0c;将字符集改成gbk试试。步骤如下&#xff1a;1.查看当前的字符集和语言select * fr…

【HDU - 2570】迷瘴 (贪心,水题,排序,卡精度有坑)

题干&#xff1a; 通过悬崖的yifenfei&#xff0c;又面临着幽谷的考验—— 幽谷周围瘴气弥漫&#xff0c;静的可怕&#xff0c;隐约可见地上堆满了骷髅。由于此处长年不见天日&#xff0c;导致空气中布满了毒素&#xff0c;一旦吸入体内&#xff0c;便会全身溃烂而死。 幸好…

oracle 1天后,Oracle Code One - 第1天 精彩亮点回顾

原标题&#xff1a;Oracle Code One - 第1天 精彩亮点回顾原文作者&#xff1a;Padmini Murthy 产品营销总监2018年Oracle CodOracle CodeOne大会实况 – 第1天2018年Oracle CodeOne大会开幕第一天&#xff0c;精彩纷呈&#xff0c;乐趣繁多。从Developers Exchange活动的欢畅交…

oracle 控制文件冗余,Oracle 添加冗余控制文件 for RAC On Linux

萌哒萌哒的分割线注&#xff1a;添加冗余控制文件期间需要有关库操作&#xff0c;需注意&#xff01;&#xff01;&#xff01;备份控制文件SQL> alter session set tracefile_identifier‘backupctrl‘;Session altered.SQL> alter database backup controlfile to trac…

linux socket bind 内核详解,Socket与系统调用深度分析(示例代码)

1、 什么是系统调用操作系统通过系统调用为运行于其上的进程提供服务。当用户态进程发起一个系统调用&#xff0c; CPU 将切换到 内核态 并开始执行一个 内核函数 。 内核函数负责响应应用程序的要求&#xff0c;例如操作文件、进行网络通讯或者申请内存资源等。在Linux中系统调…

【UVA - 11729】Commando War (贪心,时间调度问题)

题干&#xff1a;&#xff08;Uva不放题干了&#xff09; 题目大意&#xff1a;&#xff08;实在是自己懒得写网上找了一个&#xff09; 解题报告&#xff1a; 调度问题&#xff0c;直接贪心出完成任务需要的时间最长的那个人排序&#xff0c;就行了。 方法正确性的证明以前也…

linux系统键盘记录器,可截获到 QQ 密码 键盘记录器源码

由于 QQ 密码做了特殊的保护&#xff0c;所以通过远程注入得到密码框内容以及通过钩子来得到键盘消息均不能探测到 QQ 的密码&#xff0c;但是通过对键盘驱动的过滤却是可以记录下 QQ 密码输入期间的内容&#xff0c;附上源码。#define DBG 1#include #include #include "…