【链接】 我是链接,点我呀:)

【题意】

【题解】

模拟了一两下。。
然后发现。
对于每一个前缀。
组成的新的最小字典序的字符串
要么是s[i]+reverse(前i-1个字符经过操作形成的最大字典序的字符串);或者是 (前i-1个字符经过操作形成的最小字典序的字符串)+s[i]
因为最大字典序,翻转一下,然后把s[i]放前面。。显然更可能得到较小字典序的字符串。
这个最大字典序的字符串类似处理一下就Ok.

【代码】

#include <bits/stdc++.h>
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--) using namespace std; const int N = 1000; string s;
string tempma = "",tempmi ="";
string ma,mi;
vector<int> v1,v2,tv1,tv2; int main()
{
ios::sync_with_stdio(0),cin.tie(0);
cin >> s;
for (int i = 0;i < (int)s.size();i++){
ma = tempma + s[i];mi = tempmi + s[i];
v1.push_back(0);v2.push_back(0);
tv1 = v1;tv2 = v2;
//no operation reverse(tempmi.begin(),tempmi.end());
if (ma<s[i]+tempmi){
v1 = tv2;
v1[(int)v1.size()-1] = 1;
ma = s[i]+tempmi;
} reverse(tempma.begin(),tempma.end());
if (mi>s[i]+tempma){
v2 = tv1;
v2[(int)v2.size()-1] = 1;
mi = s[i]+tempma;
}
tempmi = mi;tempma = ma;
}
for (int i = 0;i < (int)v2.size();i++){
cout<<v2[i]<<' ';
}
return 0;
}

【Codeforces Round #519 by Botan Investments C】 Smallest Word的更多相关文章

  1. 【Codeforces Round #519 by Botan Investments E】Train Hard, Win Easy

    [链接] 我是链接,点我呀:) [题意] [题解] 设每个人做第一题.第二题的分数分别为x,y 我们先假设没有仇视关系. 即每两个人都能进行一次训练. 那么 对于第i个人. 考虑第j个人对它的贡献 如 ...

  2. 【Codeforces Round #519 by Botan Investments A】 Elections

    [链接] 我是链接,点我呀:) [题意] [题解] 枚举k 那么另外一个人的得票就是nk-sum(ai) 找到最小的满足nk-sum(ai)>sum(ai)的k就ok了 [代码] #includ ...

  3. 【 Codeforces Round #519 by Botan Investments B】Lost Array

    [链接] 我是链接,点我呀:) [题意] [题解] 枚举k 不难根据a得到x[0..k-1] 然后再根据a[k+1..n]来验证一下得到的x是否正确就好. [代码] #include <bits ...

  4. 【Codeforces Round #519 by Botan Investments D】Mysterious Crime

    [链接] 我是链接,点我呀:) [题意] 相当于问你这m个数组的任意长度公共子串的个数 [题解] 枚举第1个数组以i为起点的子串. 假设i..j是以i开头的子串能匹配的最长的长度. (这个j可以给2. ...

  5. Codeforces Round #519 by Botan Investments

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

  6. Codeforces Round #519 by Botan Investments(前五题题解)

    开个新号打打codeforces(以前那号玩废了),结果就遇到了这么难一套.touristD题用了map,被卡掉了(其实是对cf的评测机过分自信),G题没过, 700多行代码,码力惊人.关键是这次to ...

  7. Codeforces Round #519 by Botan Investments F. Make It One

    https://codeforces.com/contest/1043/problem/F 题意 给你n个数,求一个最小集合,这个集合里面数的最大公因数等于1 1<=n<=3e5 1< ...

  8. Codeforces Round #519 by Botan Investments翻车记

    A:枚举答案即可.注意答案最大可达201,因为这个wa了一发瞬间爆炸. #include<iostream> #include<cstdio> #include<cmat ...

  9. 【Codeforces Round #519】

    A:https://www.cnblogs.com/myx12345/p/9872082.html B:https://www.cnblogs.com/myx12345/p/9872124.html ...

随机推荐

  1. Extjs显示图片

    1.首先做一个容器 xtype : 'container', // 第2行 anchor : '100%', layout : 'column', items : [{ columnWidth : 0 ...

  2. luogu1726 上白泽慧音

    题目大意 求一个有向图含节点数最多且结点编号从小到大排列字典序最小的强连通分量. 注意事项 HDU1269那道题题面.数据太弱,在这道题上把我害惨了... Dfs点u时,如果与u相连的一个点v有Dfs ...

  3. C/C++大小端模式与位域

    一.大端小端: 1.大端:指数据的高字节保存在内存的低地址中,而数据的低字节保存在内存的高地址中 例如:0x12345678 在内存中的存储为  : 0x0000 0x0001 0x0002 0x00 ...

  4. [NOI2018]归程(80pts)

    https://www.zybuluo.com/ysner/note/1219964 题面 题面太长,难以概述,[戳我][1] \(ex10pts\ tree\) \(50pts\ n\leq1500 ...

  5. E20170911-hm

    specification n.     规格; 说明书; 详述;

  6. 图结构练习—BFSDFS—判断可达性(BFS)

    http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2138 注意该图为有向图,1000个点应该最多有 ...

  7. POJ 2976 裸的01分数规划

    题意:给你n个数对(认为是a数组和b数组吧),从中取n-m个数对,如果选第i个数对,定义x[i]=1,求R=∑(a[i]*x[i])/∑(b[i]*x[i])取得最大值时R的值.输出R*100(保留到 ...

  8. asp.net限制了上传文件大小为..M,解决方法

    asp.net限制了上传文件大小为4M,在:在web.config里加下面一句,加在<System.web></System.web>之间如下:<system.web&g ...

  9. 基于artDialog的扩展

    /* * * 引用此文件必须引用以下两个资源文件,并且还要引用jQuery * <link href="ui-dialog.css" rel="stylesheet ...

  10. Spring boot (12) tomcat jdbc连接池

    默认连接池 tomcat jdbc是从tomcat7开始推出的一个连接池,相比老的dbcp连接池要优秀很多,spring boot将tomcat jdbc作为默认的连接池,只要在pom.xml中引入了 ...