cf1043C. Smallest Word(贪心)
题意
Sol
这题打cf的时候真的是脑残,自己造了个abcdad的数据开心的玩了半天一脸懵逼。。。最后还好ycr大佬给了个思路不然就凉透了。。。
首先不难看出我们最后一定可以把字符串弄成\(aaaabbb\)的形式,若当前位和下一位不一样就直接转就行了
注意特判一下最后一个位置
/*
*/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#include<vector>
#include<set>
#include<queue>
#include<cmath>
#include<tr1/unordered_map>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/hash_policy.hpp>
#define Pair pair<int, int>
#define MP(x, y) make_pair(x, y)
#define fi first
#define se second
//#define int long long
#define LL long long
#define ull unsigned long long
#define rg register
#define pt(x) printf("%d ", x);
//#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1<<22, stdin), p1 == p2) ? EOF : *p1++)
//char buf[(1 << 22)], *p1 = buf, *p2 = buf;
//char obuf[1<<24], *O = obuf;
//void print(int x) {if(x > 9) print(x / 10); *O++ = x % 10 + '0';}
//#define OS *O++ = ' ';
using namespace std;
//using namespace __gnu_pbds;
const int MAXN = 1e5 + 10, INF = 1e9 + 10, mod = 998244353;
const double eps = 1e-9;
inline int read() {
char c = getchar();
int x = 0, f = 1;
while(c < '0' || c > '9') {if(c == '-') f = -1;c = getchar();}
while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x * f;
}
int N, flag[MAXN];
string s, r;
string RE(string s, int pre) {
for(int i = 0; i < pre; i++) swap(s[i], s[pre - i]);
return s;
}
main() {
cin >> s;
int N = s.length();
for(int i = 0; i < N; i++) {
if(s[i] != s[i + 1])
s = RE(s, i), flag[i] = 1;
// cout << s << endl;
}
string a = s, b = RE(s, N - 1);
//cout << a << " " << b << endl;
if(flag[N - 1] && (b < a)) flag[N - 1] = 0;
for(int i = 0; i < N; i++) printf("%d ", flag[i]);
return 0;
}
cf1043C. Smallest Word(贪心)的更多相关文章
- [题解]Codeforces Round #519 - C. Smallest Word
[题目] C. Smallest Word [描述] IA有一个由若干个'a'和'b'组成的字符串,IA可以翻转该字符串的任意长的前缀,IA想通过这样的操作得到一个字典序最小的字符串,求一种可能的翻转 ...
- 【CF1043C】Smallest Word(构造)
题意:给定一个由a和b构成的字符串,可以选择翻转或不翻转他的每个前缀,翻转记为1不翻转记为0,求能将字符串排序的字典序最小的操作序列 n<=1e3 思路:考虑极长的一段a [t,w] 翻转t-1 ...
- POJ 2718 Smallest Difference(贪心 or next_permutation暴力枚举)
Smallest Difference Description Given a number of distinct decimal digits, you can form one integer ...
- C. Smallest Word
链接 [http://codeforces.com/contest/1043/problem/C] 题意 给你一个只包含a,b的字符串,有一种操作把第1个字符到第i个字符的子串进行反转,问要使最后字符 ...
- 【Codeforces Round #519 by Botan Investments C】 Smallest Word
[链接] 我是链接,点我呀:) [题意] [题解] 模拟了一两下.. 然后发现. 对于每一个前缀. 组成的新的最小字典序的字符串 要么是s[i]+reverse(前i-1个字符经过操作形成的最大字典序 ...
- CodeChef - AMLEX-Poetic word
题目链接 Dhinwaji is an acclaimed poet and likes to play with words and letters. He has bought some sti ...
- Codeforces 1043 - A/B/C/D/E/F - (Undone)
链接:http://codeforces.com/contest/1043 A - Elections - [水水水水题] 题意: 我和另一个人竞争选举,共有 $n$ 个人投票,每个人手上有 $k$ ...
- Codeforces Round #519 by Botan Investments
Codeforces Round #519 by Botan Investments #include<bits/stdc++.h> #include<iostream> #i ...
- Codeforces Round #519
题目链接:传送门 A. Elections (思维+暴力) 思路: 从最小的k开始枚举就好了- -. #include <bits/stdc++.h> using namespace ...
随机推荐
- Kafka:Consumer
1.预览 1.1 消费者组(Consumer Group) 一个consumer group可能有若干个consumer实例 同一个group里面,topic的每条信息只能被发送到group下的一个c ...
- oracle for update for update nowait
对数据进行查询操作后,或提示ORA-00054错误,这时选定行的资源被占用,资源正忙.其他程序或者用户在占用着此行数据或者此表. 直接查询. select * from A1 t ; 此时取到的数据 ...
- 【算法笔记】B1051 复数乘法
题目链接:https://pintia.cn/problem-sets/994805260223102976/problems/994805274496319488 思路: 难点在于对复数其他形式的认 ...
- Q844 比较含退格的字符串
给定 S 和 T 两个字符串,当它们分别被输入到空白的文本编辑器后,判断二者是否相等,并返回结果. # 代表退格字符. 示例 1: 输入:S = "ab#c", T = " ...
- Hystrix - 踩坑回忆
1.Unable to connect to Command Metric Stream 异常 Finchley版本使用Hystrix存在此问题.网上常规解决思路: @Bean public Serv ...
- Ntp客户端
function parseMsg (buffer) { if (buffer.length !== 48) return; const pkt = {}, now = new Date().getT ...
- Android开发多媒体应用之SoundPool的使用的代码
内容过程中,把写内容过程中比较好的内容段记录起来,下面的内容是关于Android开发多媒体应用之SoundPool的使用的内容,希望对各位也有用途. public class MainActivity ...
- dotnetCore增加MiddleWare的Run,Use Map MapThen四个扩展方法
dotnetCore增加MiddleWare的Run,Use Map MapThen四个扩展方法 http://www.mamicode.com/info-detail-1439628.html
- spark第八篇:与Phoenix整合
spark sql可以与hbase交互,比如说通过jdbc,但是实际使用时,一般是利用phoenix操作hbase.此时,需要在项目中引入phoenix-core-4.10.0-HBase-1.2.j ...
- 仔细说明CLOSE_WAIT状态的原因
CLOSE_WAIT状态!!! 服务器收到客户端FIN报文后 服务器端口回复了ack,没有回复FIN报文. 1 说明客户端后面不会再向服务器发送用户层的数据了, 2 客户端 没有回复FIN 报文嘛 ...