题目链接: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;就按照上面的构造方法。

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

#include <iostream>
#include <cstring>
using namespace std;
int a , b , l , r , ans , T;
char s[200];
bool vis[27];
int dfs(char cp) {
int count = 0;
for(int i = 0 ; i < a ; i++) s[i] = ('a' + i);
for(int i = a ; i < a + b ; i++) s[i] = cp;
memset(vis , false , sizeof(vis));
for(int i = b ; i < a + b ; i++) vis[s[i] - 'a'] = true;
int sta = a + b , ed = 0;
while(sta < 2 * a + b) {
while(vis[ed]) ed++;
s[sta] = ed + 'a';
sta++ , ed++;
}
for(int i = 2 * a + b ; i < T ; i++) s[i] = s[i - 1];
memset(vis , false , sizeof(vis));
if(l <= r) {
for(int i = l ; i <= r ; i++) {
if(!vis[s[i] - 'a']) {
count++ , vis[s[i] - 'a'] = true;
}
}
}
else {
for(int i = 0 ; i <= r ; i++) {
if(!vis[s[i] - 'a']) {
count++ , vis[s[i] - 'a'] = true;
}
}
for(int i = l ; i < T ; i++) {
if(!vis[s[i] - 'a']) {
count++ , vis[s[i] - 'a'] = true;
}
}
}
return count;
}
int main() {
cin >> a >> b >> l >> r;
l-- , r--;
if(a <= b) ans = a + 1;
else ans = 2 * a - b;
T = 2 * (a + b);
if(r - l >= T);
else {
r %= T , l %= T;
for(int i = 0 ; i < a ; i++) {
ans = min(dfs('a' + i) , ans);
}
}
cout << ans << endl;
return 0;
}

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】The identity used sign the executable is no longer valid.

    之前就遇到过这个问题,如图: 今天又遇到了,证书过期的问题. 需要访问苹果开发者的官网 http://developer.apple.com 来解决. 参考:How to fix “The ident ...

  2. angularjs通信以及postmessage与iframe通信

    这篇文章是用markdown工具写的,有需要的可以使用vscode打开   # angularjs 控制器.组件之间的通信 ## 一.基于事件的方式 此方式下,主要通过 angularjs 内置指令` ...

  3. light oj 1159 - Batman LCS

    学过简单动态规划的人应该对最长公共子序列的问题很熟悉了,这道题只不过多加了一条字符串变成三条了,还记得,只要把状态变成三维的即可. //http://lightoj.com/volume_showpr ...

  4. 如何使用Arrays工具类操作数组

    介绍 我们要先知道Arrays 是什么. java.util.Arrays 类是 JDK 提供的一个工具类主要用来操作数组,比如数组的复制转换等各种方法,Arrays 的方法都是静态方法可以通过Arr ...

  5. idea 新建不了servlet文件 方法(1)

    在pem.xml中添加较新版本的servletapi包 <dependency> <groupId>javax.servlet</groupId> <arti ...

  6. 0x33 同余

    目录 定义 同余类与剩余系 费马小定理 欧拉定理 证明: 欧拉定理的推论 证明: 应用: 定义 若整数 $a$ 和整数 $b$ 除以正整数 $m$ 的余数相等,则称 $a,b$ 模 $m$ 同余,记为 ...

  7. Draw.io

    如何给类图增加一个字段? 选中一个字段,然后按 Ctrl +Enter 即可. 参考:Add row to class diagram - stackoverflow

  8. CodeForces 939F Cutlet

    洛谷题目页面传送门 & CodeForces题目页面传送门 题意见洛谷里的翻译. 这是一道毒瘤的div. 2 F,我是不可能比赛的时候做出来的... (以下设两面都要煎\(n\)分钟,有\(m ...

  9. Springboot源码分析之番外篇

    摘要: 大家都知道注解是实现了java.lang.annotation.Annotation接口,眼见为实,耳听为虚,有时候眼见也不一定是真实的. /** * The common interface ...

  10. Python变量类型说明

    Python中的变量不需要声明,直接赋值便是声明和定义的过程 每个变量在内存中创建,都包括变量的标识.名称和数据这些信息 每个变量在使用前必须赋值 counter = 100 #正数变量 miles ...