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} \) ...
随机推荐
- PAT 1066 图像过滤
https://pintia.cn/problem-sets/994805260223102976/problems/994805266514558976 图像过滤是把图像中不重要的像素都染成背景色, ...
- Eclipse:An internal error occurred during: "Building workspace". GC overhead limit exceeded
http://blog.csdn.net/shaozhang872196/article/details/18552273 http://www.cnblogs.com/sonofelice/p/52 ...
- Docker for windows 入门二(Kitematic的使用)
Kitematic下载地址:https://download.docker.com/kitematic/Kitematic-Windows.zip 下载Kitematic,解压后运行,可以登录连接Do ...
- C/C++关键字 new/delete和malloc/free
基本上new/delete来自于C++,作为对对象的创建.因此在使用new创建对象时候new会调用对象的构造函数,同样delete会调用对象的析构函数释放对象.而malloc/free操作的是直接的内 ...
- vuex最简单、最详细的入门文档
如果你在使用 vue.js , 那么我想你可能会对 vue 组件之间的通信感到崩溃 . 我在使用基于 vue.js 2.0 的UI框架 ElementUI 开发网站的时候 , 就遇到了这种问题 : 一 ...
- 一个简单的Oracle和 SQLSERVER 重建所有表索引的办法
1. SQLSERVER 使用微软自带的存储过程 exec sp_msforeachtable 'DBCC DBREINDEX(''?'')' 2. Oracle的办法: select 'alter ...
- 解决vmware与主机无法连通的问题
我们选择NAT方式,来实现Ubuntu的静态IP地址配置. 打开VMware,在顶部依次选择:编辑 > 虚拟网路编辑器,打开虚拟网路编辑器:去掉VMnet0和VMnet1,只保留VMnet8.然 ...
- loadrunner基础学习笔记三
运行时设置: 打开运行时设置:任务窗格中-选择回放-点击运行时设置按钮 1 重复执行次数:=2 2 步:控制迭代时间间隔 3 日志设置:指出要在运行测试期间记录的信息量 4 思考时间:可以在cont ...
- LoadRunner12 Java Vuser API语法举例
// 检查点 web.reg_find("Text=\"retCode\":\"0000\"",new String[]{"FAI ...
- c++ 为自定义类添加stl遍历器风格的遍历方式
为仿照stl的遍历风格,实现对自定义类型的遍历. 1. 需要遍历的基础结构: struct ConnectionPtr { int id_; int port_; string addr_; //st ...