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

【题意】

【题解】

模拟了一两下。。
然后发现。
对于每一个前缀。
组成的新的最小字典序的字符串
要么是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. 【POJ 2983】Is the Information Reliable?(差分约束系统)

    id=2983">[POJ 2983]Is the Information Reliable? (差分约束系统) Is the Information Reliable? Time L ...

  2. 查看scn headroom变化趋势的几种方法

    查看scn headroom变化趋势的几种方法 scn headroom问题,本文不做解释. 本文为自己的总结,脚本来自于oracle sr技术project师. 转载请注明出处http://blog ...

  3. Android实战简易教程-第四十一枪(显示倒计时的Button-适用于获取验证码)

    近期在做获取验证码的功能.考虑到优良的用户体验,决定制作一个拥有倒计时提示的Button按钮,在网上查了一些资料,非常是简单的就能实现.我写了一个小Demo,大家能够应用到自己的项目中. 一.代码 1 ...

  4. Coursera Algorithms week2 栈和队列 练习测验: Stack with max

    题目原文: Stack with max. Create a data structure that efficiently supports the stack operations (push a ...

  5. php导出mysql源码

    件名:db_backup.php 源代码如下: 复制代码 代码如下: <?php ini_set("max_execution_time", "180") ...

  6. 命令行启动ubuntu

    图形模式下,首先进入终端: 1. 运行 sudo vi/etc/default/grub 2. 找到 GRUB_CMDLINE_LINUX_DEFAULT=”quiet splash” 3.改为 GR ...

  7. Jquery中绑定事件的异同

    谈论jquery中bind(),live(),delegate(),on()绑定事件方式 1. Bind() $(selector).bind(event,data,function) Event:必 ...

  8. .Net Core 学习(二)上篇

    用Visual Studio和ASP.NET Core MVC创建Web API 1.启动Visual Studio.从文件菜单,选择新建>项目.选择ASP.NET Core Web Appli ...

  9. swift-自定义TabBar工具栏

    class EBTAppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? func application(ap ...

  10. python--4、装饰器

    装饰器(Decorator) 使用场景:为被装饰器装饰的函数增加功能,但又不希望修改函数的定义,即在代码运行期间动态增加功能. 装饰器更多的用于后期功能升级而不是编写新的代码.装饰器不光能装饰函数,也 ...