CodeForces 346C Number Transformation II
题解:
对于操作2来说, a - a % x[i] 就会到左边离a最近的x[i]的倍数。
也就是说 [ k * x[i] + 1, (k+1)* x[i] -1 ]这段区间的的数都会走到 k * x[i]上。
所以对于每个位置都先计算出他到右边最远的覆盖位置。
然后在反着求出每个位置能往左走走到的最远的位置。
代码:
#include<bits/stdc++.h>
using namespace std;
#define Fopen freopen("___.txt","r",stdin);
#define LL long long
#define ULL unsigned LL
#define fi first
#define se second
#define pb push_back
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define lch(x) tr[x].son[0]
#define rch(x) tr[x].son[1]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const LL _INF = 0xc0c0c0c0c0c0c0c0;
const LL mod = (int)1e9+;
const int N = 1e6 + ;
const int M = 3e7;
vector<int> in[N], out[N];
int x[N], to[N], rto[N];
int n;
int main(){
scanf("%d", &n);
for(int i = ; i <= n; ++i) scanf("%d", &x[i]);
int f = ;
int a, b;
scanf("%d%d", &a, &b);
sort(x+, x++n);
n = unique(x+, x++n) - (x+);
for(int i = ; i <= a-b; ++i) rto[i] = i + ;
for(int i = ; i <= n; ++i){
LL start = b / x[i] * x[i];
if(start < b) start += x[i];
while(start < a){
LL r = start + x[i] - ;
if(r > a) r = a;
rto[start-b] = max(rto[start-b], (int)(r-b));
start = r + ;
}
}
// cout << "ok1" << endl;
for(int l = , r = ; l <= a-b; ++l){
int nr = rto[l];
while(r <= nr){
to[r] = l;
++r;
}
}
int ans = , now = a-b;
while(now){
ans++;
now = to[now];
}
cout << ans << endl; return ;
}
CodeForces 346C Number Transformation II的更多相关文章
- Codeforces 346C Number Transformation II 构造
题目链接:点击打开链接 = = 990+ms卡过 #include<stdio.h> #include<iostream> #include<string.h> # ...
- Codeforces 346C Number Transformation II 贪心(复杂度计算)
题意及思路:https://www.cnblogs.com/liuzhanshan/p/6560499.html 这个做法的复杂度看似是O(n ^ 2),实际上均摊是O(n)的.我们考虑两种极端数据: ...
- CodeForces346 C. Number Transformation II
C. Number Transformation II time limit per test 1 second memory limit per test 256 megabytes input s ...
- Codeforces 251C Number Transformation
Number Transformation 我们能发现这个东西是以2 - k的lcm作为一个循环节, 然后bfs就好啦. #include<bits/stdc++.h> #define L ...
- cf201.div1 Number Transformation II 【贪心】
1 题目描述: 被给一系列的正整数x1,x2,x3...xn和两个非负整数a和b,通过下面两步操作将a转化为b: 1.对当前的a减1. 2.对当前a减去a % xi (i=1,2...n). 计算a转 ...
- CSUOJ 1299 - Number Transformation II 打表预处理水DP
http://122.207.68.93/OnlineJudge/problem.php?id=1299 第二个样例解释.. 3 6 3->4->6..两步.. 由此可以BFS也可以DP. ...
- Codeforces 251C Number Transformation DP, 记忆化搜索,LCM,广搜
题意及思路:https://blog.csdn.net/bossup/article/details/37076965 代码: #include <bits/stdc++.h> #defi ...
- hdu4952 Number Transformation (找规律)
2014多校 第八题 1008 2014 Multi-University Training Contest 8 4952 Number Transformation Number Transform ...
- 4.Single Number && Single Number (II)
Single Number: 1. Given an array of integers, every element appears twice except for one. Find that ...
随机推荐
- iOS开发 8小时时差问题
今天调试遇到时间计算的问题,发现怎么算都会有差别,后来仔细观察,发现有8小时的时差…… 这篇文章解释的很好,用到了,因此记之. ios有关时间打印出来差8小时的问题
- vue3.0中的双向数据绑定方法
熟悉vue的人都知道在vue2.x之前都是使用object.defineProperty来实现双向数据绑定的 而在vue3.0中这个方法被取代了 1. 为什么要替换Object.definePrope ...
- Vue中动态(import 、require)显示img图片
vue中,经常会遇到显示图片的问题, 如果是一个普通组件的话,那么这样就可以了 <img src="../assets/images/avtor.jpg" width=&qu ...
- 警惕!CAF效应导致PCB漏电
最近碰到一个PCB漏电的问题,起因是一款低功耗产品,本来整机uA级别的电流,常温老化使用了一段时间后发现其功耗上升,个别样机功耗甚至达到了mA级别.仔细排除了元器件问题,最终发现了一个5V电压点,在产 ...
- 用CSS来定义<p>标签,要求实现以下效果:字体颜色再IE6下为黑色,IE7下为红色,IE8下为绿色,其他浏览器下为黄色。
<!DOCTYPE html><html><head><meta charset="utf-8"><meta name=&qu ...
- python_Tensorflow学习(三):TensorFlow学习基础
一.矩阵的基本操作 import tensorflow as tf # 1.1矩阵操作 sess = tf.InteractiveSession() x = tf.ones([2, 3], &qu ...
- JWT详解
目录 1.前言 2.JWT的数据结构 2.1 Header 2.2 Payload 2.3 Signature 2.4 Base64URL 3. JWT的实现 1.前言 定义:JSON Web T ...
- MyBatis 一级缓存、二级缓存全详解(一)
目录 MyBatis 一级缓存.二级缓存全详解(一) 什么是缓存 什么是MyBatis中的缓存 MyBatis 中的一级缓存 初探一级缓存 探究一级缓存是如何失效的 一级缓存原理探究 还有其他要补充的 ...
- MyBatis之#{} and ${}
#{} 和 ${} 之间最大的差别就是 #{}会在使用的时候被加上 ‘’ 引号, ${}直接传值,不做任何处理 1.#{}对传入的参数会做预编译,也就是会当做字符串来处理 select * from ...
- 微信小程序云开发报错解决: Setting data field "openid" to undefined is invalid.
最近在学习微信小程序云开发,刚一开始就遇到了问题. 点击获取openid的时候控制台开始报错: [云函数] [login] user openid: undefined VM97:1 Setting ...