题目链接: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. 【Python】Django 的邮件引擎用法详解!!(调用163邮箱为例)

    1. send_mall()方法介绍 位置: 在django.core.mail模块提供了send_mail()来发送邮件. 方法参数: send_mail(subject, message, fro ...

  2. 拉格朗日对偶性(Lagrange duality)

    目录 拉格朗日对偶性(Lagrange duality) 1. 从原始问题到对偶问题 2. 弱对偶与强对偶 3. KKT条件 Reference: 拉格朗日对偶性(Lagrange duality) ...

  3. 证明线程池ThreadPoolExecutor的核心线程数,最大线程数,队列长度的关系

    关于线程池的几个参数,很多人不是很清楚如何配置,他们之间是什么关系,我用代码来证明一下. package www.itbac.com; import java.util.concurrent.*; p ...

  4. Android 属性动画实战

    什么是属性动画? 属性动画可以通过直接更改 View 的属性来实现 View 动画.例如: 通过不断的更改 View 的坐标来实现让 View 移动的效果: 通过不断的更改 View 的背景来实现让 ...

  5. Pandas 库之 DataFrame

    How to use DataFrame ? 简介 创建 DataFrame 查看与筛选数据:行列选取 DataFrame 数据操作:增删改 一.About DataFrame DataFrame 是 ...

  6. Python 命令行之旅 —— 初探 argparse

    『讲解开源项目系列』启动--让对开源项目感兴趣的人不再畏惧.让开源项目的发起者不再孤单.跟着我们的文章,你会发现编程的乐趣.使用和发现参与开源项目如此简单.欢迎联系我们给我们投稿,让更多人爱上开源.贡 ...

  7. powerdesign进军(二)--oracle数据源配置

    目录 资源下载(oracle客户端) 配置 查看系统的数据源 powerdesign 连接数据库 title: powerdesign进军(二)--oracle数据源配置 date: 2019-05- ...

  8. 记一次JPA遇到的奇葩错误——本地sql不识别表名的别名

    记一次JPA遇到的奇葩错误——本地sql不识别表名的别名 报错:Unknown column 'our' in 'field list' 起因:需要本地sql查询后,分页返回自定义对象.报错信息如下: ...

  9. ABAP-根据采购订单行项目统计供应商未清额和已清额

    1.传入和传出表结构都是一样的: FUNCTION zmm_fm_po_invence. *"------------------------------------------------ ...

  10. MTFlexbox自动化埋点探索

    1. 背景 跨平台动态化技术是目前移动互联网领域的重点关注方向,它既能节约人力,又能实现业务快速上线的需求.经过十年的发展,美团App已经变成了一个承载众多业务的超级平台,众多的业务方对业务形态的快速 ...