题意:给定一个由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. Redis常用诊断命令

    1.info 命令查看redis信息,可以指定要查看的section名 sections:Server,clients,memory,persistence,stats,replication,cpu ...

  2. 第四篇:python操作数据库时的传参问题

    python在操作数据库执行sql的时候我们经常会遇到传参问题,以下是我总结的几种方法: 1.格式化字符串 city = 'beijing'cur.execute(“SELECT * FROM %s ...

  3. python3中文件的读与写

    Python open() 函数用于打开一个文件,并返回文件对象,在对文件进行处理过程都需要使用到这个函数,如果该文件无法被打开,会抛出错误 完整语法:open(file, mode='r', buf ...

  4. Green Space【绿色空间】

    Green Space Living in an urban area with green spaces has a long-lasting positive impact on people's ...

  5. vscode运行C/C++程序及配置

    安装vscdoe,安装tdm-gcc-64编译器,这样可以自动把mingw的目录添加到环境变量中,其实安装其他编译器本版都可以,只要手动添加环境变量即可.平台win10-64位.此文参考了哔哩哔哩的配 ...

  6. P2485 [SDOI2011]计算器

    P2485 [SDOI2011]计算器 题目描述 你被要求设计一个计算器完成以下三项任务: 1.给定y.z.p,计算y^z mod p 的值: 2.给定y.z.p,计算满足xy ≡z(mod p)的最 ...

  7. java基础_单例模式

    java开发实战经典 --单例模式 从CSDN以及博客园的相关文章学习的,摘做笔记. “java中单例模式是一种常见的设计模式,单例模式的写法有好几种,这里主要介绍三种:懒汉式单例.饿汉式单例.登记式 ...

  8. luogu2120 [ZJOI2007]仓库建设

    大米饼写的太棒辣qwqqwq #include <iostream> #include <cstdio> using namespace std; typedef long l ...

  9. IOS开发---菜鸟学习之路--(六)-UITableView几个方法的使用说明

    对于UITableView的基础使用我这边就不做重复介绍了 我重点就来介绍下如何实现大部分新闻的界面.也就是第一条记录显示大图片下面加一段文字说明 然后剩下来的内容全部显示为文字图片的格式 其实要做到 ...

  10. 【Single Num II】cpp

    题目: Given an array of integers, every element appears three times except for one. Find that single o ...