题意

一个01串,可以有两种操作:①在末尾添加parity(a);②删除开头的一个字符。其中parity(a),当串中1的个数为奇数时为1,偶数时为0。问某个01串是否可以通过若干操作变成另一个01串。

思路

简单分析一下可以先发现一个事情:当一个串的1的个数为奇数时它最多可以再增加1个1;而当1的个数是偶数时,1的个数不可能再增加。这是一个决定性的性质。 再进一步发现,奇数个数1的01串可以任意减少1的个数,以及,任意一个串可以移位。以及,当1的个数为偶数个时,可以通过在末尾任意补0以及移位操作转换成长度一定、1个数一定的任意01串。而奇数个数1的01串可以通过先增加1个1,然后补0、移位,再减一个1也能转换成长度一定、1个数一定的任意01串。 所以我们只要统计起始串和目标串的长度,当起始串1个数为奇数时可以+1,然后如果起始串长度>=目标串,则一定可以通过减少1、补0、移位等操作转换成目标串。

代码

[cpp] #include <iostream> #include <cstdio> #include <cmath> #include <algorithm> #include <string> #include <cstring> #include <vector> #include <set> #include <stack> #include <queue> #define MID(x,y) ((x+y)/2) #define MEM(a,b) memset(a,b,sizeof(a)) #define REP(i, begin, end) for (int i = begin; i <= end; i ++) using namespace std; typedef long long LL; typedef vector <int> VI; typedef set <int> SETI; typedef queue <int> QI; typedef stack <int> SI; int main(){ //freopen("test.in", "r", stdin); //freopen("test.out", "w", stdout); string s1, s2; cin >> s1 >> s2; int len1 = count(s1.begin(), s1.end(), '1'), len2 = count(s2.begin(), s2.end(), '1'); if (len1 & 1) len1 ++; if (len1 >= len2){ puts("YES"); } else{ puts("NO"); } return 0; } [/cpp]

转载于:https://www.cnblogs.com/AbandonZHANG/p/4114107.html

CodeForces 297A Parity Game (脑补题)相关推荐

  1. codeforces round div2,3周赛补题计划(从开学到期末)

    1. 本学期场次 从2020.09.19-2021.01.18,一共18周. 题号 场次 日期 备注 1475 Codeforces Round #697 (Div. 3) 1.25 1474 Cod ...

  2. Codeforces Round #807 (Div. 2)补题

    C. Mark and His Unfinished Essay https://codeforces.com/contest/1705/problem/C 会卡long long,下面解法62ms过 ...

  3. Codeforces Round #723 (Div. 2)补题

    水题,只需要将序列分成两部分即可,一部分是大的,一部分是小的. #include <cstdio> #include <iostream> #include <algor ...

  4. Codeforces Round #702 (Div. 3)补题

    题目链接 文章目录 A. Dense Array B. Balanced Remainders C. Sum of Cubes D. Permutation Transformation E. Acc ...

  5. Codeforces Round #787 (Div. 3)补题

    目录: 官网链接 E. Replace With the Previous, Minimize F. Vlad and Unfinished Business G. Sorting Pancakes ...

  6. Codeforces 补题记录

    首先总结一下前段时间遇到过的一些有意思的题. Round #474 (Div. 1 + Div. 2, combined)   Problem G 其实关键就是n这个数在排列中的位置. 这样对于一个排 ...

  7. Codeforces Round #701 (Div. 2)赛后补题报告(A~D)

    Codeforces Round #701 (Div. 2)赛后补题报告(A~D) A. Add and Divide 原题信息 http://codeforces.com/contest/1485/ ...

  8. Codeforces补题记录(1)

    文章目录 Codeforces补题记录(1) 1.Codeforces Round #632 (Div. 2)(2020.4.11) A.Little Artem B.Kind Anton *C.Eu ...

  9. 2020 China Collegiate Programming Contest Weihai Site补题部分

    A. Golden Spirit 签到题,首先把所有老人带到对岸,然后在对休息讨论一下即可. #define IO ios::sync_with_stdio(false);cin.tie();cout ...

最新文章

  1. IIS APPPOOL\DefaultAppPool 登录失败的解决方法
  2. 如何限制oracle数据库表的输出记录条数
  3. 干货分享:单片机编程学习攻略!
  4. iphone4 短信截获
  5. F.孤独(牛客小白月赛39)
  6. exists查询慢_我大意了!这些问题让我的MySQL慢了十倍。
  7. python编写的心得_Python开发之我的小心得
  8. 设计模式(外观模式)
  9. java 4.0 下载_poi.jar包下载 Apache POI 4.0.0 正式版 Office文档jar包 官方免费版 支持Java8+ 下载-脚本之家...
  10. Matlab求极限图解
  11. 为什么选择WordPress作为企业CMS?
  12. 数组去重几种常见的方法
  13. HIT-2022年春季学期《软件构造》Lab 1实验心得
  14. 【2020-10-28】DS12C887+驱动
  15. 1.初接触思科模拟器
  16. 1697_python编程_assertions and exceptions
  17. vue 移动端 实现 一像素实线
  18. 英语日常口语对话(7)
  19. Python实现照片、视频一键压缩及备份源代码
  20. MATLAB插值笔记

热门文章

  1. case when 效率高不高_扬州效率高的拍摄抖音短视频平台
  2. git lib 创建新的项目在某个路径下_版本控制管理工具git的使用
  3. anaconda使用github代码_使用这几款插件,能让你在GitHub看代码的效率翻倍
  4. Unity3D-声音处理
  5. Linux下的设备管理、磁盘分区及分区类型的修改
  6. Android 切换卡(TabWidget)
  7. Vue.js 基础学习
  8. (2)树莓派挂载外部硬盘
  9. 2017/08/22 工作日志
  10. SYN攻击原理以及检测防范技术