题意:给定一个由a和b构成的字符串,可以选择翻转或不翻转他的每个前缀,翻转记为1不翻转记为0,求能将字符串排序的字典序最小的操作序列

n<=1e3

思路:考虑极长的一段a [t,w]

翻转t-1与w就能把这段a移到最前面

 #include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<map>
#include<queue>
#include<vector>
#include<ctime>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef vector<int> VI;
#define fi first
#define se second
#define MP make_pair
#define N 210000
#define M 130
#define MOD 1000000007
#define eps 1e-8
#define pi acos(-1) char a[N];
int b[N],c[N]; int main()
{
scanf("%s",a+);
int n=strlen(a+);
for(int i=;i<=n;i++)
if(a[i]=='a') c[i]=;
else c[i]=; int i=;
memset(b,,sizeof(b));
while(i<=n)
{
i++;
if(c[i]==||i>n) continue;
int t=i;
int w=i;
while(i+<=n&&c[i+]==){i++; w++;}
b[t-]^=; b[w]^=;
}
for(int i=;i<=n-;i++) printf("%d ",b[i]);
printf("%d",b[n]);
return ;

【CF1043C】Smallest Word(构造)的更多相关文章

  1. cf1043C. Smallest Word(贪心)

    题意 题目链接 Sol 这题打cf的时候真的是脑残,自己造了个abcdad的数据开心的玩了半天一脸懵逼...最后还好ycr大佬给了个思路不然就凉透了... 首先不难看出我们最后一定可以把字符串弄成\( ...

  2. [题解]Codeforces Round #519 - C. Smallest Word

    [题目] C. Smallest Word [描述] IA有一个由若干个'a'和'b'组成的字符串,IA可以翻转该字符串的任意长的前缀,IA想通过这样的操作得到一个字典序最小的字符串,求一种可能的翻转 ...

  3. C. Smallest Word

    链接 [http://codeforces.com/contest/1043/problem/C] 题意 给你一个只包含a,b的字符串,有一种操作把第1个字符到第i个字符的子串进行反转,问要使最后字符 ...

  4. Canada Cup 2016 C. Hidden Word 构造模拟题

    http://codeforces.com/contest/725/problem/C Each English letter occurs at least once in s. 注意到题目有这样一 ...

  5. 【Codeforces Round #519 by Botan Investments C】 Smallest Word

    [链接] 我是链接,点我呀:) [题意] [题解] 模拟了一两下.. 然后发现. 对于每一个前缀. 组成的新的最小字典序的字符串 要么是s[i]+reverse(前i-1个字符经过操作形成的最大字典序 ...

  6. CodeChef - AMLEX-Poetic word

    题目链接  Dhinwaji is an acclaimed poet and likes to play with words and letters. He has bought some sti ...

  7. Codeforces 1043 - A/B/C/D/E/F - (Undone)

    链接:http://codeforces.com/contest/1043 A - Elections - [水水水水题] 题意: 我和另一个人竞争选举,共有 $n$ 个人投票,每个人手上有 $k$ ...

  8. Codeforces Round #519 by Botan Investments

    Codeforces Round #519 by Botan Investments #include<bits/stdc++.h> #include<iostream> #i ...

  9. Codeforces Round #519

    题目链接:传送门   A. Elections (思维+暴力) 思路: 从最小的k开始枚举就好了- -. #include <bits/stdc++.h> using namespace ...

随机推荐

  1. nodejs 用户登录密码md5加密

    jade文件 div.login ul.inp-content  li span= '用户名:' input.ui-input1#input1(placeholder='请输入手机号')  li sp ...

  2. linux下安装redis和使用

    http://www.linuxidc.com/Linux/2014-05/101979.htm

  3. linux下通过phpize为php在不重新编译php情况下安装模块memcache

    通过phpize为php在不重新编译php情况下安装模块memcache 1. 下载    wget http://pecl.php.net/get/memcache-2.2.4.tgz     解压 ...

  4. linux通配符知识

    注意:linux通配符和三剑客(grep,awk,sed)正则表达式是不一样的,因此,代表的意义也是有较大区别的. 通配符一般用户命令行bash环境,而linux正则表达式用于grep,sed,awk ...

  5. thinkphp 5数据库操作

    1.原生sql $options=Db::table('__MALL_POST__') ->alias('m') ->join('__MALL_CATEGORY_VALUE__ v','m ...

  6. Python 枚举类源码解析

    1. EnumMeta 元类编程,生成类的类,可以动态生成类. 用法: type(name, bases, dict) name -> 类名: str bases -> 基类: tuple ...

  7. 安装 ubuntu 后,使用 sed 更换国内源

    cd /etc/aptsed -i "s/archive.ubuntu.com/mirrors.aliyun.com/g" /etc/apt/sources.list也可以使用 1 ...

  8. 笔记-HTTP代理

    笔记-HTTP代理 1.      基本原理 所谓代理,一个重要的目的是身份伪装,让被访问端无法正辨识访问者的身份. 那么下一个问题是服务器从哪些信息上来识别访问端的身份. 以php http服务器为 ...

  9. Python linecache模块

    Table of Contents 1. linecache 1.1. 其它 2. 参考资料 linecache 今天分享一个python的小模块: linecache, 可以用它方便地获取某一文件某 ...

  10. poj2631 Roads in the North(求树的直径)

    Roads in the North Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2941   Accepted: 144 ...