原题链接

参考自

问题描述:一个长度为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(构造)的更多相关文章

  1. Codeforces Gym 100187K K. Perpetuum Mobile 构造

    K. Perpetuum Mobile Time Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/pro ...

  2. gym/102021/K GCPC18 背包dp算不同数和的可能

    gym/102021/K 题意: 给定n(n<=60)个直线 ,长度<=1000; 可以转化为取 计算 ans = (sum  + 10 - g) / ( n + 1)  在小于5的条件下 ...

  3. 【中途相遇法】【STL】BAPC2014 K Key to Knowledge (Codeforces GYM 100526)

    题目链接: http://codeforces.com/gym/100526 http://acm.hunnu.edu.cn/online/?action=problem&type=show& ...

  4. 字典集合Dictionary<K,V>和构造的应用==>>体检套餐项目

    效果 首先,我们先来准备我们需要的类 1.检查项目类 using System; using System.Collections.Generic; using System.Linq; using ...

  5. Codeforces Gym 100425H H - Football Bets 构造

    H - Football BetsTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/ ...

  6. 【Codeforces Gym 100725K】Key Insertion

    Codeforces Gym 100725K 题意:给定一个初始全0的序列,然后给\(n\)个查询,每一次调用\(Insert(L_i,i)\),其中\(Insert(L,K)\)表示在第L位插入K, ...

  7. codeforces gym 100971 K Palindromization 思路

    题目链接:http://codeforces.com/gym/100971/problem/K K. Palindromization time limit per test 2.0 s memory ...

  8. CF1157D N Problems During K Days(简单构造)

    题目 题目 原数据是水成啥样了,\(<\longrightarrow <=,>=\longrightarrow <=,\)这也能过 被\(hack\)后身败名裂 做法 简单的贪 ...

  9. CF gym 101933 K King's Colors —— 二项式反演

    题目:http://codeforces.com/gym/101933/problem/K 其实每个点的颜色只要和父亲不一样即可: 所以至多 i 种颜色就是 \( i * (i-1)^{n-1} \) ...

随机推荐

  1. Jquery 组 表单验证

    <!DOCTYPE html><html lang="zh-cn"><head> <meta charset="utf-8&qu ...

  2. Flutter & Dart

    Flutter & Dart https://www.dartlang.org/install https://flutter.dev/ https://flutter.dev/docs/ge ...

  3. 一本通1601【例 5】Banknotes

    1601:[例 5]Banknotes 时间限制: 1000 ms         内存限制: 524288 KB [题目描述] 原题来自:POI 2005 Byteotian Bit Bank (B ...

  4. BZOJ2716 [Violet]天使玩偶(cdq分治+树状数组)

    非常裸的KD-tree.然而我没学啊. 考虑如何离线求一个点在平面中的曼哈顿最近点. 绝对值显得有点麻烦,于是把绝对值拆开分情况讨论一波.对于横坐标小于该点的,记录对于纵坐标的前缀x+y最大值和后缀x ...

  5. Code First 重复外键(简单方法)

    之前有说过  Code First 重复外键   的一种解决方案.   http://blog.csdn.net/hanjun0612/article/details/50478134 虽然可以解决问 ...

  6. 18 Zabbix 新增map中的icon图标

    点击返回:自学Zabbix之路 18 Zabbix 新增map中的icon图标 zabbix系统默认会带有许多的icon图标,但对于特殊需求人群可能无法满足,那就需要新增icon图标. 通过Admin ...

  7. LCT模板(指针版)

    本来是想做THUWC2017的泰勒展开xLCT题的-- 然后觉得数组写很麻烦-- 然后就决定挑战指针版-- 然后写得全是BUG-- 与BUG鏖战三千年后,有了这个指针版LCT板子! #include ...

  8. UOJ#7. 【NOI2014】购票 | 线段树 凸包优化DP

    题目链接 UOJ #7 题解 首先这一定是DP!可以写出: \[f[i] = \min_{ancestor\ j} \{f[j] + (d[j] - d[i]) * p[i] + q[i]\}\] 其 ...

  9. 软Raid50制作

    =====创建Raid50的步骤====== 1.创建分区[root@localhost ~]# fdisk /dev/sdb[root@localhost ~]# fdisk /dev/sdc[ro ...

  10. android + eclipse + 后台静默安装(一看就会)

      首先要说到三个类. import android.content.pm.IPackageInstallObserver; import android.content.pm.IPackageIns ...