codeforces 820 C. Mister B and Boring Game(找规律)
题目链接: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(找规律)的更多相关文章
- HDU 5793 A Boring Question (找规律 : 快速幂+乘法逆元)
A Boring Question Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...
- Codeforces D. Little Elephant and Interval(思维找规律数位dp)
题目描述: Little Elephant and Interval time limit per test 2 seconds memory limit per test 256 megabytes ...
- codeforces 820 D. Mister B and PR Shifts(思维)
题目链接:http://codeforces.com/contest/820/problem/D 题意:求.有一种操作 k = 0: shift p1, p2, ... pn, k = 1: shif ...
- Codeforces Round #347 (Div. 2) C. International Olympiad 找规律
题目链接: http://codeforces.com/contest/664/problem/C 题解: 这题最关键的规律在于一位的有1989-1998(9-8),两位的有1999-2098(99- ...
- 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 ...
- Codeforces 1091D New Year and the Permutation Concatenation 找规律,数学 B
Codeforces 1091D New Year and the Permutation Concatenation https://codeforces.com/contest/1091/prob ...
- codeforces#1136 C. Nastya Is Transposing Matrices(找规律)
题意:给出两个n*m的矩阵,每次操作可以让一个正方形矩阵行列交换.问,在无限次操作下,第一个矩阵能否变成第二个矩阵 分析:先把操作限定在2*2的矩阵中.这样对角线上的元素就可以随意交换.也就是说,如果 ...
- codeforces D. Queue 找规律+递推
题目链接: http://codeforces.com/problemset/problem/353/D?mobile=true H. Queue time limit per test 1 seco ...
- Codeforces Gym 100114 A. Hanoi tower 找规律
A. Hanoi tower Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100114 Descript ...
随机推荐
- 【iOS】UIImage 等比率缩放
这两天处理引导页面的时候遇到了图片略大的问题,上网查找后找到了解决方法.用的是 UIImage 的等比率缩放,虽然不难,但之前没接触过,故记之. 代码如下: - (UIImage *)scaleIma ...
- 华为路由交换综合实验 ---IA阶段
目录 华为路由交换综合实验 ---IA阶段 实验拓扑 实验需求 华为路由交换综合实验 ---IA阶段 实验拓扑 实验需求 根据拓扑合理规划IP地址以及VLANIf地址(PC1属于运营部,PC2属于市场 ...
- 前端工程师和设计师必备的chrome插件
Google Chrome是最好用的几个浏览器之一,今天我来分享下自己收集的一系列Chrome插件,希望对大家的学习和工作有帮助. 注:你可以通过复制链接或者在谷歌商店搜索相应插件的名称来获取以下插件 ...
- Dubbo里面线程池的拒绝策略
Dubbo里面线程池的拒绝策略 public class AbortPolicyWithReport extends ThreadPoolExecutor.AbortPolicy { protecte ...
- [ PyQt入门教程 ] PyQt5基本控件使用:消息弹出、用户输入、文件对话框
本文主要介绍PyQt界面实现中常用的消息弹出对话框.提供用户输入的输入框.打开文件获取文件/目录路径的文件对话框.学习这三种控件前,先想一下它们使用的主要场景: 1.消息弹出对话框.程序遇到问题需要退 ...
- sqoop 密码别名模式 --password-alias
sqoop要使用别名模式隐藏密码 1.首先使用命令创建别名 hadoop credential create xiaopengfei -provider jceks://hdfs/user/pass ...
- Django:在OS X环境下连接MySQL数据库
正常的安装只需要执行以下2条命令: $ brew install mysql-connector-c $ pip3 install mysqlclient 但在执行 pip3 install mysq ...
- java并发编程(十一)----(JUC原子类)基本类型介绍
上一节我们说到了基本原子类的简单介绍,这一节我们先来看一下基本类型: AtomicInteger, AtomicLong, AtomicBoolean.AtomicInteger和AtomicLong ...
- vue面试题整理vuejs基础知识整理
初级参考 1.v-show 与 v-if 区别 v-show 是css隐藏,v-if是直接销毁和创建,所以频繁切换的适合用v-show 2.计算属性和 watch 的区别 计算属性是自动监听依赖值的变 ...
- 高性能MySQL之事物
一.概念 事务到底是什么东西呢?想必大家学习的时候也是对事务的概念很模糊的.接下来通过一个经典例子讲解事务. 银行在两个账户之间转账,从A账户转入B账户1000元,系统先减少A账户的1000元,然后再 ...