题目链接:http://codeforces.com/contest/820/problem/C

题解:显然a<=b的规律很好找只要

例如a=2,b=5,只要这样排列就行abbbbbbabbbbbbabbbbbb....

然后a>b的规律是

例如a=5,b=2,只要这样的排列就行abcdeeeabfghhhabcdeeeanfghhh.....

当然满足这些条件的话就可以求出大于r-l>T的结果(T=2*(a+b))

显然if(a <= b) ans = a + 1; else ans = 2 * a - b;就按照上面的构造方法。

然后小与一周期的时候就直接暴力判断,这个很好判断详见代码。

  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4. int a , b , l , r , ans , T;
  5. char s[200];
  6. bool vis[27];
  7. int dfs(char cp) {
  8. int count = 0;
  9. for(int i = 0 ; i < a ; i++) s[i] = ('a' + i);
  10. for(int i = a ; i < a + b ; i++) s[i] = cp;
  11. memset(vis , false , sizeof(vis));
  12. for(int i = b ; i < a + b ; i++) vis[s[i] - 'a'] = true;
  13. int sta = a + b , ed = 0;
  14. while(sta < 2 * a + b) {
  15. while(vis[ed]) ed++;
  16. s[sta] = ed + 'a';
  17. sta++ , ed++;
  18. }
  19. for(int i = 2 * a + b ; i < T ; i++) s[i] = s[i - 1];
  20. memset(vis , false , sizeof(vis));
  21. if(l <= r) {
  22. for(int i = l ; i <= r ; i++) {
  23. if(!vis[s[i] - 'a']) {
  24. count++ , vis[s[i] - 'a'] = true;
  25. }
  26. }
  27. }
  28. else {
  29. for(int i = 0 ; i <= r ; i++) {
  30. if(!vis[s[i] - 'a']) {
  31. count++ , vis[s[i] - 'a'] = true;
  32. }
  33. }
  34. for(int i = l ; i < T ; i++) {
  35. if(!vis[s[i] - 'a']) {
  36. count++ , vis[s[i] - 'a'] = true;
  37. }
  38. }
  39. }
  40. return count;
  41. }
  42. int main() {
  43. cin >> a >> b >> l >> r;
  44. l-- , r--;
  45. if(a <= b) ans = a + 1;
  46. else ans = 2 * a - b;
  47. T = 2 * (a + b);
  48. if(r - l >= T);
  49. else {
  50. r %= T , l %= T;
  51. for(int i = 0 ; i < a ; i++) {
  52. ans = min(dfs('a' + i) , ans);
  53. }
  54. }
  55. cout << ans << endl;
  56. return 0;
  57. }

codeforces 820 C. Mister B and Boring Game(找规律)的更多相关文章

  1. HDU 5793 A Boring Question (找规律 : 快速幂+乘法逆元)

    A Boring Question Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others ...

  2. Codeforces D. Little Elephant and Interval(思维找规律数位dp)

    题目描述: Little Elephant and Interval time limit per test 2 seconds memory limit per test 256 megabytes ...

  3. codeforces 820 D. Mister B and PR Shifts(思维)

    题目链接:http://codeforces.com/contest/820/problem/D 题意:求.有一种操作 k = 0: shift p1, p2, ... pn, k = 1: shif ...

  4. Codeforces Round #347 (Div. 2) C. International Olympiad 找规律

    题目链接: http://codeforces.com/contest/664/problem/C 题解: 这题最关键的规律在于一位的有1989-1998(9-8),两位的有1999-2098(99- ...

  5. Codeforces Round #327 (Div. 2) C. Median Smoothing 找规律

    C. Median Smoothing Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/591/p ...

  6. Codeforces 1091D New Year and the Permutation Concatenation 找规律,数学 B

    Codeforces 1091D New Year and the Permutation Concatenation https://codeforces.com/contest/1091/prob ...

  7. codeforces#1136 C. Nastya Is Transposing Matrices(找规律)

    题意:给出两个n*m的矩阵,每次操作可以让一个正方形矩阵行列交换.问,在无限次操作下,第一个矩阵能否变成第二个矩阵 分析:先把操作限定在2*2的矩阵中.这样对角线上的元素就可以随意交换.也就是说,如果 ...

  8. codeforces D. Queue 找规律+递推

    题目链接: http://codeforces.com/problemset/problem/353/D?mobile=true H. Queue time limit per test 1 seco ...

  9. Codeforces Gym 100114 A. Hanoi tower 找规律

    A. Hanoi tower Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100114 Descript ...

随机推荐

  1. 【iOS】UIImage 等比率缩放

    这两天处理引导页面的时候遇到了图片略大的问题,上网查找后找到了解决方法.用的是 UIImage 的等比率缩放,虽然不难,但之前没接触过,故记之. 代码如下: - (UIImage *)scaleIma ...

  2. 华为路由交换综合实验 ---IA阶段

    目录 华为路由交换综合实验 ---IA阶段 实验拓扑 实验需求 华为路由交换综合实验 ---IA阶段 实验拓扑 实验需求 根据拓扑合理规划IP地址以及VLANIf地址(PC1属于运营部,PC2属于市场 ...

  3. 前端工程师和设计师必备的chrome插件

    Google Chrome是最好用的几个浏览器之一,今天我来分享下自己收集的一系列Chrome插件,希望对大家的学习和工作有帮助. 注:你可以通过复制链接或者在谷歌商店搜索相应插件的名称来获取以下插件 ...

  4. Dubbo里面线程池的拒绝策略

    Dubbo里面线程池的拒绝策略 public class AbortPolicyWithReport extends ThreadPoolExecutor.AbortPolicy { protecte ...

  5. [ PyQt入门教程 ] PyQt5基本控件使用:消息弹出、用户输入、文件对话框

    本文主要介绍PyQt界面实现中常用的消息弹出对话框.提供用户输入的输入框.打开文件获取文件/目录路径的文件对话框.学习这三种控件前,先想一下它们使用的主要场景: 1.消息弹出对话框.程序遇到问题需要退 ...

  6. sqoop 密码别名模式 --password-alias

    sqoop要使用别名模式隐藏密码 1.首先使用命令创建别名 hadoop credential create xiaopengfei  -provider jceks://hdfs/user/pass ...

  7. Django:在OS X环境下连接MySQL数据库

    正常的安装只需要执行以下2条命令: $ brew install mysql-connector-c $ pip3 install mysqlclient 但在执行 pip3 install mysq ...

  8. java并发编程(十一)----(JUC原子类)基本类型介绍

    上一节我们说到了基本原子类的简单介绍,这一节我们先来看一下基本类型: AtomicInteger, AtomicLong, AtomicBoolean.AtomicInteger和AtomicLong ...

  9. vue面试题整理vuejs基础知识整理

    初级参考 1.v-show 与 v-if 区别 v-show 是css隐藏,v-if是直接销毁和创建,所以频繁切换的适合用v-show 2.计算属性和 watch 的区别 计算属性是自动监听依赖值的变 ...

  10. 高性能MySQL之事物

    一.概念 事务到底是什么东西呢?想必大家学习的时候也是对事务的概念很模糊的.接下来通过一个经典例子讲解事务. 银行在两个账户之间转账,从A账户转入B账户1000元,系统先减少A账户的1000元,然后再 ...