GYM 101173 K.Key Knocking(构造)
问题描述:一个长度为3*n的01串,每次可以翻转连续的两个字符,要求至多翻转n次使得这个3*n的串至少有2*n个连续的段且相邻两端不一样(就是连续的0算一段,然后连续的1,…)
解法:每三个一组,只要能把每组分成两段而且和前面的不连着最后段数一定不小于2*n,例如前一个是1(0同理),当前组只有八种情况(冒号前表示操作前状态,冒号后表示操作后的状态):
000:011
001:001
010:010
011:011
100:010
101:101
110:101
111:001
故每种情况至多操作一次即可,扫一遍即得到操作位置
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<ctime>
using namespace std;
typedef long long ll;
#define INF 0x3f3f3f3f
#define maxn 111111
char s[maxn*];
int ans[maxn],res;
int main()
{
while(~scanf("%s",s+))
{
s[]='';
int n=strlen(s+);
res=;
for(int i=;i+<=n;i+=)
{
int a=s[i]-'',b=s[i+]-'',c=s[i+]-'';
if(s[i-]=='')
{
if(a==&&b==&&c==)ans[res++]=i;
else if(a==&&b==&&c==)ans[res++]=i+,s[i+]='';
else if(a==&&b==&&c==)ans[res++]=i;
else if(a==&&b==&&c==)ans[res++]=i+,s[i+]='';
}
else
{
if(a==&&b==&&c==)ans[res++]=i+,s[i+]='';
else if(a==&&b==&&c==)ans[res++]=i;
else if(a==&&b==&&c==)ans[res++]=i+,s[i+]='';
else if(a==&&b==&&c==)ans[res++]=i;
}
}
printf("%d\n",res);
for(int i=;i<res;i++)printf("%d%c",ans[i],i==res-?'\n':' ');
}
return ;
}
GYM 101173 K.Key Knocking(构造)的更多相关文章
- Codeforces Gym 100187K K. Perpetuum Mobile 构造
K. Perpetuum Mobile Time Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/pro ...
- gym/102021/K GCPC18 背包dp算不同数和的可能
gym/102021/K 题意: 给定n(n<=60)个直线 ,长度<=1000; 可以转化为取 计算 ans = (sum + 10 - g) / ( n + 1) 在小于5的条件下 ...
- 【中途相遇法】【STL】BAPC2014 K Key to Knowledge (Codeforces GYM 100526)
题目链接: http://codeforces.com/gym/100526 http://acm.hunnu.edu.cn/online/?action=problem&type=show& ...
- 字典集合Dictionary<K,V>和构造的应用==>>体检套餐项目
效果 首先,我们先来准备我们需要的类 1.检查项目类 using System; using System.Collections.Generic; using System.Linq; using ...
- Codeforces Gym 100425H H - Football Bets 构造
H - Football BetsTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/ ...
- 【Codeforces Gym 100725K】Key Insertion
Codeforces Gym 100725K 题意:给定一个初始全0的序列,然后给\(n\)个查询,每一次调用\(Insert(L_i,i)\),其中\(Insert(L,K)\)表示在第L位插入K, ...
- codeforces gym 100971 K Palindromization 思路
题目链接:http://codeforces.com/gym/100971/problem/K K. Palindromization time limit per test 2.0 s memory ...
- CF1157D N Problems During K Days(简单构造)
题目 题目 原数据是水成啥样了,\(<\longrightarrow <=,>=\longrightarrow <=,\)这也能过 被\(hack\)后身败名裂 做法 简单的贪 ...
- CF gym 101933 K King's Colors —— 二项式反演
题目:http://codeforces.com/gym/101933/problem/K 其实每个点的颜色只要和父亲不一样即可: 所以至多 i 种颜色就是 \( i * (i-1)^{n-1} \) ...
随机推荐
- ASP.NET MVC自定义异常处理
1.自定义异常处理过滤器类文件 新建MyExceptionAttribute.cs异常处理类文件
- 面象对象设计原则之一:单一职责原则(Single Responsibility Principle, SRP)
单一职责原则是最简单的面向对象设计原则,它用于控制类的粒度大小.单一职责原则定义如下:单一职责原则(Single Responsibility Principle, SRP):一个类只负责一个功能领域 ...
- [转帖]召冠总的 SQLSERVER常用的性能诊断语句. --保存学习备查
CopyFrom https://www.cnblogs.com/zhaoguan_wang /*常规服务器动态管理对象包括:dm_db_*:数据库和数据库对象dm_exec_*:执行用户代码和关联的 ...
- css 按钮凹陷的感觉
.login-btn{ margin-top: 60rpx !important; background-color:transparent !important; width: 40%; margi ...
- FICO基础知识(四)
What is the organizational structure for CO? Operating Concern 经营组织 Controlling Area 成本控制范围 Profit c ...
- OneZero——Review报告会
1. 时间: 2016年4月20日. 2. 成员: X 夏一鸣 * 组长 (博客:http://www.cnblogs.com/xiaym896/), G 郭又铭 (博客:http://www.cnb ...
- 给kali linux2.0装一个中文输入法
没有中文输入法好痛苦啊.. 毕竟做了无限网卡,虚拟机和主机可以完完全全当两台设备使用了,所以kali还是需要一个中文输入法才方便. 由于使用的是比较新的kali版本和源,现在安装fcitx已经可以直接 ...
- BZOJ2213[Poi2011]Difference——DP
题目描述 A word consisting of lower-case letters of the English alphabet ('a'-'z') is given. We would li ...
- BZOJ4372 烁烁的游戏(动态点分治+线段树)
建出点分树,每个节点维护其作为点分树上lca对子树内点的贡献,线段树维护即可,同时另开一个线段树以减掉父亲重复的贡献. #include<iostream> #include<cst ...
- String的实例化与static final修饰符
String两种实例化方式 一种是通过双引号直接赋值的方式,另外一种是使用标准的new调用构造方法完成实例化.如下: String str = "abcd"; String str ...