【题目链接】:http://codeforces.com/contest/709/problem/C

【题意】



让你改变一个字符串的子集(连续的一段);

->这一段的每个字符的字母都变成之前的一个;

即b->a或是a>z;

然后使得剩下的字符串的字典序最小;

【题解】



优先更改前面的字符;

所以遇到第一个不是a的字符->改!

从那个字符开始只要不是a就一直改就好;

hack点;

有说

exactly once->也就是说



aaa

不能全都不改;

把最后那个a改成z(损失最小)

永远不要低估CF的C题。。



【完整代码】

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define lson l,m,rt<<1
  4. #define rson m+1,r,rt<<1|1
  5. #define LL long long
  6. #define rep1(i,a,b) for (int i = a;i <= b;i++)
  7. #define rep2(i,a,b) for (int i = a;i >= b;i--)
  8. #define mp make_pair
  9. #define ps push_back
  10. #define fi first
  11. #define se second
  12. #define rei(x) scanf("%d",&x)
  13. #define rel(x) scanf("%lld",&x)
  14. #define ref(x) scanf("%lf",&x)
  15. typedef pair<int, int> pii;
  16. typedef pair<LL, LL> pll;
  17. const int dx[9] = { 0,1,-1,0,0,-1,-1,1,1 };
  18. const int dy[9] = { 0,0,0,-1,1,-1,1,-1,1 };
  19. const double pi = acos(-1.0);
  20. const int N = 1e5+1000;
  21. char s[N];
  22. int len;
  23. int main()
  24. {
  25. //freopen("F:\\rush.txt", "r", stdin);
  26. bool fi = false;
  27. scanf("%s", s + 1);
  28. len = strlen(s + 1);
  29. rep1(i, 1, len){
  30. if (s[i] == 'a') continue;
  31. int j = i;
  32. while (j + 1 <= len && s[j + 1] != 'a') j++;
  33. rep1(k, i, j) s[k]--;
  34. fi = true;
  35. break;
  36. }
  37. if (!fi) s[len]='z';
  38. printf("%s", s + 1);
  39. //printf("\n%.2lf sec \n", (double)clock() / CLOCKS_PER_SEC);
  40. return 0;
  41. }

【codeforces 709C】Letters Cyclic Shift的更多相关文章

  1. codeforces 709C C. Letters Cyclic Shift(贪心)

    题目链接: C. Letters Cyclic Shift 题意: 现在一串小写的英文字符,每个字符可以变成它前边的字符即b-a,c-a,a-z这样,选一个字串变换,使得得到的字符串字典序最小; 思路 ...

  2. Codeforces Problem 708A Letters Cyclic Shift

     题目链接: http://codeforces.com/problemset/problem/708/A 题目大意: 从字符串s中挑选出一个子串(非空),将该子串中的每个字母均替换成前一个字母,如' ...

  3. Codeforces 708A Letters Cyclic Shift

    A. Letters Cyclic Shift time limit per test:1 second memory limit per test:256 megabytes input:stand ...

  4. AIM Tech Round 3 (Div. 1) A. Letters Cyclic Shift 贪心

    A. Letters Cyclic Shift 题目连接: http://www.codeforces.com/contest/708/problem/A Description You are gi ...

  5. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  6. 【codeforces div3】【E. Cyclic Components】

    E. Cyclic Components time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  7. 【codeforces 761C】Dasha and Password(动态规划做法)

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  8. 【codeforces 761C】Dasha and Password(贪心+枚举做法)

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  9. 【19.77%】【codeforces 570D】Tree Requests

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

随机推荐

  1. java笔记线程两种方式模拟电影院卖票

    public class SellTicketDemo { public static void main(String[] args) { // 创建三个线程对象 SellTicket st1 = ...

  2. GG_DataAccess 数据库访问层使用dapper操作

    3.5.GG_DataAccess 数据库访问层使用dapper操作 和Model实体类同理,tt模板已写好,需要的可加qq群:547765059  自己下载.

  3. loadrunner11 安装破解,汉化包

    说说自己的心痛史,好不容易安装了loadrunner 11 居然浏览器不支持,我的系统是win8.1,ie浏览器最低支持ie11,我还能说啥子...其他浏览器试过了依旧是不可以!!所以我安装了一个虚拟 ...

  4. LOJ#503. 「LibreOJ β Round」ZQC 的课堂(容斥+FHQTreap)

    题面 传送门 题解 首先\(x\)和\(y\)两维互相独立,可以分开考虑,我们以\(x\)为例 我们把\(x\)做个前缀和,那么就是问有多少\(i\)满足\(s_is_{i-1}<0\),其中\ ...

  5. [转]C语言字符串操作总结大全(超详细)

    1)字符串操作 strcpy(p, p1) 复制字符串 strncpy(p, p1, n) 复制指定长度字符串 strcat(p, p1) 附加字符串 strncat(p, p1, n) 附加指定长度 ...

  6. BFS(两点搜索) FZOJ 2150 Fire Game

    题目传送门 题意:'#'表示草地,两个人在草地上点火,相邻的草地会烧起来,每烧一格等1秒,问最少要等几秒草地才烧完 分析:这题和UVA 11624 Fire!有点像,那题给定了两个点,这题两点不确定, ...

  7. vue中引入swiper插件

    这里我们使用npm的方式安装swiper插件. 1.npm install vue-awesome-swiper --save 2.在main.js文件中引入文件 import Vue from 'v ...

  8. C#基础 集合

    //数组定义的时候 //需要定义数据类型 //需要定义初始长度 //int [] array = new int[5]; //int a = array.Length; //集合 //ArrayLis ...

  9. springboot与dubbo整合遇到的坑

    整合环境: dubbo 2.6.2 springboot 2.1.5 遇到的问题:服务一直无法注册到zookeeper注册中心 项目结构: 使用application.properties文件: 配置 ...

  10. Python之绘图和可视化

    Python之绘图和可视化 1. 启用matplotlib 最常用的Pylab模式的IPython(IPython --pylab) 2. matplotlib的图像都位于Figure对象中. 可以使 ...