CodeForces 297A Parity Game (脑补题)
题意
一个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 (脑补题)相关推荐
- codeforces round div2,3周赛补题计划(从开学到期末)
1. 本学期场次 从2020.09.19-2021.01.18,一共18周. 题号 场次 日期 备注 1475 Codeforces Round #697 (Div. 3) 1.25 1474 Cod ...
- Codeforces Round #807 (Div. 2)补题
C. Mark and His Unfinished Essay https://codeforces.com/contest/1705/problem/C 会卡long long,下面解法62ms过 ...
- Codeforces Round #723 (Div. 2)补题
水题,只需要将序列分成两部分即可,一部分是大的,一部分是小的. #include <cstdio> #include <iostream> #include <algor ...
- Codeforces Round #702 (Div. 3)补题
题目链接 文章目录 A. Dense Array B. Balanced Remainders C. Sum of Cubes D. Permutation Transformation E. Acc ...
- Codeforces Round #787 (Div. 3)补题
目录: 官网链接 E. Replace With the Previous, Minimize F. Vlad and Unfinished Business G. Sorting Pancakes ...
- Codeforces 补题记录
首先总结一下前段时间遇到过的一些有意思的题. Round #474 (Div. 1 + Div. 2, combined) Problem G 其实关键就是n这个数在排列中的位置. 这样对于一个排 ...
- Codeforces Round #701 (Div. 2)赛后补题报告(A~D)
Codeforces Round #701 (Div. 2)赛后补题报告(A~D) A. Add and Divide 原题信息 http://codeforces.com/contest/1485/ ...
- Codeforces补题记录(1)
文章目录 Codeforces补题记录(1) 1.Codeforces Round #632 (Div. 2)(2020.4.11) A.Little Artem B.Kind Anton *C.Eu ...
- 2020 China Collegiate Programming Contest Weihai Site补题部分
A. Golden Spirit 签到题,首先把所有老人带到对岸,然后在对休息讨论一下即可. #define IO ios::sync_with_stdio(false);cin.tie();cout ...
最新文章
- IIS APPPOOL\DefaultAppPool 登录失败的解决方法
- 如何限制oracle数据库表的输出记录条数
- 干货分享:单片机编程学习攻略!
- iphone4 短信截获
- F.孤独(牛客小白月赛39)
- exists查询慢_我大意了!这些问题让我的MySQL慢了十倍。
- python编写的心得_Python开发之我的小心得
- 设计模式(外观模式)
- java 4.0 下载_poi.jar包下载 Apache POI 4.0.0 正式版 Office文档jar包 官方免费版 支持Java8+ 下载-脚本之家...
- Matlab求极限图解
- 为什么选择WordPress作为企业CMS?
- 数组去重几种常见的方法
- HIT-2022年春季学期《软件构造》Lab 1实验心得
- 【2020-10-28】DS12C887+驱动
- 1.初接触思科模拟器
- 1697_python编程_assertions and exceptions
- vue 移动端 实现 一像素实线
- 英语日常口语对话(7)
- Python实现照片、视频一键压缩及备份源代码
- MATLAB插值笔记