题目链接: http://codeforces.com/problemset/problem/708/A 题目大意: 从字符串s中挑选出一个子串(非空),将该子串中的每个字母均替换成前一个字母,如'b'换成'a','c'换成'b',以此类推,特别的,'a'要换成'z',问经过一次转换之后,字典序最小的字符串s为多少.注意“exactly one non-empty substring”这就意味着全'a'串也要变,即字符串"aaa",替换其中的字母(会使得字典序比原来大),但又要使字典…
A. Letters Cyclic Shift time limit per test:1 second memory limit per test:256 megabytes input:standard input output:standard output You are given a non-empty string s consisting of lowercase English letters. You have to pick exactly one non-empty su…
题目链接: C. Letters Cyclic Shift 题意: 现在一串小写的英文字符,每个字符可以变成它前边的字符即b-a,c-a,a-z这样,选一个字串变换,使得得到的字符串字典序最小; 思路: 贪心,尽量让前边的字典序变小; AC代码: #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #inclu…
[题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一个; 即b->a或是a>z; 然后使得剩下的字符串的字典序最小; [题解] 优先更改前面的字符; 所以遇到第一个不是a的字符->改! 从那个字符开始只要不是a就一直改就好; hack点: 有说 exactly once->也就是说 像 aaa 不能全都不改; 把最后那个a改成z(损失最…
A. Letters Cyclic Shift 题目连接: http://www.codeforces.com/contest/708/problem/A Description You are given a non-empty string s consisting of lowercase English letters. You have to pick exactly one non-empty substring of s and shift all its letters 'z'…
题意:给定一个字符串,让你把它的一个子串字符都减1,使得总字符串字典序最小. 析:由于这个题是必须要有一个字串,所以你就要注意这个只有一个字符a的情况,其他的就从开始减 1,如果碰到a了就不减了,如果到最后一位了还没开始减, 就减最后一位. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <c…
贪心. 肯定是两个$a$之间的那些字符都$-1$,没有$a$就全部$-1$.如果输入的串全是$a$,那么把最后一个$a$改成$z$. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<vector> #inc…
You are given a non-empty string s consisting of lowercase English letters. You have to pick exactly one non-empty substring of s and shift all its letters 'z' 'y' 'x' 'b' 'a' 'z'. In other words, each character is replaced with the previous characte…
A. Hongcow Learns the Cyclic Shift 题目连接: http://codeforces.com/contest/745/problem/A Description Hongcow is learning to spell! One day, his teacher gives him a word that he needs to learn to spell. Being a dutiful student, he immediately learns how t…
Largest Smallest Cyclic Shift 题目来源: Atcoder Code Festival 2017 Qual B Problem F 题目大意: 有\(X\)个字符'a',\(Y\)个字符'b',\(Z\)个字符'c'.用它们组成字符串,求最小表示的最大值. 思路: 贪心.首先将所有由单个字符构成的字符串插入到一个multiset<string>中,每次选取最小串\(s\)和最大串\(t\).此时最小表示一定是由\(s\)开头的,而将\(t\)接在\(s\)后面可以让…