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} \) ...
随机推荐
- 【转帖】Systemd 入门教程:命令篇
Systemd 入门教程:命令篇 Copy From http://www.ruanyifeng.com/blog/2016/03/systemd-tutorial-commands.html 感觉 ...
- GS使用HTTPS登录的设置过程
1. Windows 增加角色服务 服务器配置管理器, 添加角色服务 增加角色功能里面有: 证书颁发机构 证书颁发机构 web注册 2. AD CS配置 主要是next操作 独立ca 根证书 等 3. ...
- pandas切片使用和column赋值
#-*- coding: utf-8 -*- #对数据进行基本的探索 #返回缺失值个数以及最大最小值 import pandas as pd datafile= '../data/air_data.c ...
- linux服务器上安装python 3.6.3
一.下载源码包 地址https://www.python.org/ftp/python/3.6.3/Python-3.6.3.tar.xz 二.解压源码包 1.下载解压工具xz #yum -y ins ...
- atan和unwrap解卷绕
要计算一个系统相频特性,就要用到反正切函数,计算机中反正切函数规定,在一.二象限中的角度为0-pi,三四象限的角度为0--pi. 若一个角度从0变到2pi,但实际得到的结果是0-pi,再由-pi-0, ...
- yield与递归的组合运用
- LOJ #6435. 「PKUSC2018」星际穿越(倍增)
题面 LOJ#6435. 「PKUSC2018」星际穿越 题解 参考了 这位大佬的博客 这道题好恶心啊qwq~~ 首先一定要认真阅读题目 !! 注意 \(l_i<r_i<x_i\) 这个条 ...
- POJ P3352 Road Construction 解题报告
P3352 Road Construction 描述 这几乎是夏季,这意味着它几乎是夏季施工时间!今年,负责岛屿热带岛屿天堂道路的优秀人士,希望修复和升级岛上各个旅游景点之间的各种道路. 道路本身也很 ...
- RabbitMQ安装详解
# RabbitMQ 消息中间件 一.安装:#安装epel源[EPEL (Extra Packages for Enterprise Linux,企业版Linux的额外软件包)rpm -Uvh htt ...
- matplotlib fill和fill_between
import numpy as np import matplotlib.pyplot as plt x = np.linspace(0, 5 * np.pi, 1000) y1 = np.sin(x ...