cf1043C. Smallest Word(贪心)】的更多相关文章

题意 题目链接 Sol 这题打cf的时候真的是脑残,自己造了个abcdad的数据开心的玩了半天一脸懵逼...最后还好ycr大佬给了个思路不然就凉透了... 首先不难看出我们最后一定可以把字符串弄成\(aaaabbb\)的形式,若当前位和下一位不一样就直接转就行了 注意特判一下最后一个位置 /* */ #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #inclu…
[题目] C. Smallest Word [描述] IA有一个由若干个'a'和'b'组成的字符串,IA可以翻转该字符串的任意长的前缀,IA想通过这样的操作得到一个字典序最小的字符串,求一种可能的翻转方案.输出是否翻转长度为k的前缀,k=1,2,...,n,n为该字符串长度. 数据范围:1<=字符串长度<=1000 [思路] 为了把第m+1个字符挪到第1个位置并保持其他字符不动,可以翻转m长的和m+1长的前缀(先后顺序不影响结果).于是,我们可以通过这样的操作把每一个'a'挪到最前面,最后就得…
题意:给定一个由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>…
Smallest Difference Description Given a number of distinct decimal digits, you can form one integer by choosing a non-empty subset of these digits and writing them in some order. The remaining digits can be written down in some order to form a second…
链接 [http://codeforces.com/contest/1043/problem/C] 题意 给你一个只包含a,b的字符串,有一种操作把第1个字符到第i个字符的子串进行反转,问要使最后字符串字典序最小那些位置需要反转, 分析 代码 #include<bits/stdc++.h> using namespace std; #define ll long long int main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie…
[链接] 我是链接,点我呀:) [题意] [题解] 模拟了一两下.. 然后发现. 对于每一个前缀. 组成的新的最小字典序的字符串 要么是s[i]+reverse(前i-1个字符经过操作形成的最大字典序的字符串);或者是 (前i-1个字符经过操作形成的最小字典序的字符串)+s[i] 因为最大字典序,翻转一下,然后把s[i]放前面..显然更可能得到较小字典序的字符串. 这个最大字典序的字符串类似处理一下就Ok. [代码] #include <bits/stdc++.h> #define rep1(…
题目链接  Dhinwaji is an acclaimed poet and likes to play with words and letters. He has bought some stickers where each sticker has a lower case english letter (a-z). The letters are indexed from 1 - 26 i.e. a has index 1, b has index 2 and so on. He ha…
链接:http://codeforces.com/contest/1043 A - Elections - [水水水水题] 题意: 我和另一个人竞争选举,共有 $n$ 个人投票,每个人手上有 $k$ 票,必须投给我或者另一个人. 现在已知每个人给另一个人投 $a_i$ 票,也就是说会给我投 $k-a_i$ 票.求最小的整数 $k$,使得我的票数严格大于另一个人. 题解: 暴力枚举 $k$. AC代码: #include<bits/stdc++.h> using namespace std; ;…
Codeforces Round #519 by Botan Investments #include<bits/stdc++.h> #include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #include<algorithm> #include<queue> #include<vect…
题目链接:传送门   A. Elections (思维+暴力) 思路: 从最小的k开始枚举就好了- -. #include <bits/stdc++.h> using namespace std; + ; int a[MAX_N]; int main() { int N; cin >> N; , sum = ; ; i <= N; i++) { scanf("%d", a+i); m = max(m, a[i]); sum += a[i]; } int a…