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 ...
随机推荐
- fastcgi main
main函数里 当kill -TERM pid 时, http://redfoxli.github.io/php-fpm-signals.html 这篇文章 说是 1)master主进程接收到sig ...
- Windows下安装Redis服务(zip)
1.官方没有 Windows版本的 Redis,官网介绍: Redis项目不正式支持Windows.但是,微软开发并维护了针对Win64的Windows版本. 2.Windows版本下载地址:http ...
- docker images 按名称过滤
docker images nihao_* 列出所有 nihao_* 正则匹配的镜像
- CAS总结
n++的问题不能保证原子操作. 因为被编译后拆分成了3个指令,先获取值,然后加一,然后写回内存.把变量声明为volatile,volatile只能保证内存可见性,但是不能保证原子性,在多线程并发下,无 ...
- jsp基础知识总结
1.了解jsp,jsp有什么有利的,有什么弊端. jsp是serlet的扩展,在web应用中,每个jsp页面都会有servlet容器生产对应的servlet. jsp通过在标准的html页面中插入ja ...
- Linux 中的rsh,ssh
第一部分 rsh 的安装与配置 http://www.ttlsa.com/linux/configure-rsh-rcp-scp-on-centos/ http://www.ahlinux.com/s ...
- SqlHelper中SqlHelperParameterCache类的用法介绍
SqlHelper类中提供了三种可以用来管理SqlParameter参数的共享方法.下面来一一讲解: 1.CacheParameterSet 将SqlParameter参数数组存储到本地缓存中 2.G ...
- 【linux】在ubuntu中使用apt-get安装oracle jdk6
在Ubuntu 12.04 LTS上安装JDK6本身并不复杂,只是目前较新版本的Ubuntu已经不支持直接通过apt-get安装了.因此,需要从Oracle官方网站下载安装包进行安装. 从Oracle ...
- AOP的最佳注入方式——MSIL注入
下载PostSharp(Visual Studio Gallery). 安装一个AOP编译器和引入PostSharp.Aspects(注意安装过程中请使用免费的Express版本),然后初步演示代码: ...
- 在Xcode中手动添加pch文件
在Xcode中手动添加pch文件: 一: 在工程中新建.pch文件,pch文件名通常用工程名字命名: 二: 在Targets->build Settings->Prefix Header ...