题目大意:有$n$个点,每个点有一个距离(从小到大给出),从第$i$个点跳一次,会跳到距离第$i$个点第$k$远的点上(若有两个点都是第$k$远,就跳到编号小的上)。问对于从每个点开始跳,跳$m$次,最后会到哪个点

题解:难点主要在处理第$k$远上(跳只需要一个类似快速幂的东西就好了,也就是倍增)。

可以维护两个指针,一个是$l$,一个是$r(r=l+k)$,且到$i$这个点时$l\leqslant i\leqslant r$。刚开始时$l=1,r=k+1$,若$p_{r+1}-p_i<p_i-p_l(p_i为第i个点的位置)$,就把$l$和$r$都加一

则第$i$个点跳到的点就是$l,r$中较远的一个,若相同就是$l$(当$r==n$时就是$l$)。

卡点:无

C++ Code:

#include <cstdio>
#define maxn 100010
int n, k, l, r;
long long m;
struct _ {
int to[maxn];
_ operator * (const _& rhs) {
_ res;
for (int i = 1; i <= n; i++) {
res.to[i] = rhs.to[to[i]];
}
return res;
}
} base, ans;
long long p[maxn];
int main() {
scanf("%d%d%lld", &n, &k, &m);
for (int i = 1; i <= n; i++) scanf("%lld", p + i);
l = 1, r = k + 1;
for (int i = 1; i <= n; i++) {
ans.to[i] = i;
while (r < n && p[i] - p[l] > p[r + 1] - p[i]) l++, r++;
if (p[i] - p[l] >= p[r] - p[i]) base.to[i] = l;
else base.to[i] = r;
}
for (; m; m >>= 1, base = base * base) if (m & 1) ans = ans * base;
for (int i = 1; i <= n; i++) printf("%d ", ans.to[i]);
puts("");
return 0;
}

[洛谷P3509][POI2010]ZAB-Frog的更多相关文章

  1. 洛谷P3502 [POI2010]CHO-Hamsters感想及题解(图论+字符串+矩阵加速$dp\&Floyd$)

    洛谷P3502 [POI2010]CHO-Hamsters感想及题解(图论+字符串+矩阵加速\(dp\&Floyd\)) 标签:题解 阅读体验:https://zybuluo.com/Junl ...

  2. [洛谷P3501] [POI2010]ANT-Antisymmetry

    洛谷题目链接:[POI2010]ANT-Antisymmetry 题目描述 Byteasar studies certain strings of zeroes and ones. Let be su ...

  3. 洛谷P3509 Frog

    题目 首先分析数据范围发现m很大,所以线性做法肯定不行,因此考虑倍增,即预处理出每个点跳1次后的位置.然后只用两个数组类似于快速幂,推出每个点跳m次后的位置. 预处理离每个点第k小的点,可以用长度为k ...

  4. 洛谷 P3496 [POI2010]GIL-Guilds

    P3496 [POI2010]GIL-Guilds 题目描述 King Byteasar faces a serious matter. Two competing trade organisatio ...

  5. 洛谷 P3507 [POI2010]GRA-The Minima Game

    P3507 [POI2010]GRA-The Minima Game 题目描述 Alice and Bob learned the minima game, which they like very ...

  6. 洛谷 P3505 [POI2010]TEL-Teleportation

    P3505 [POI2010]TEL-Teleportation 题目描述 King Byteasar is the ruler of the whole solar system that cont ...

  7. 【字符串】【hash】【倍增】洛谷 P3502 [POI2010]CHO-Hamsters 题解

        这是一道字符串建模+图论的问题. 题目描述 Byteasar breeds hamsters. Each hamster has a unique name, consisting of lo ...

  8. 洛谷P3507 [POI2010]GRA-The Minima Game

    题目描述 Alice and Bob learned the minima game, which they like very much, recently. The rules of the ga ...

  9. [洛谷P3512 [POI2010]PIL-Pilots]

    题目链接: 传送门走这里 题目分析: 感觉不是很难啊--不像是蓝题(AC量也不像)恶意评分? 少打了一个+1调了半天,就这样居然还能过60pts?我思路和题解第一篇高度重合是什么鬼啊,太过分了吧本来还 ...

随机推荐

  1. ES6 extends继承及super使用读书笔记

    extends 继承 extends 实现子类的继承 super() 表示父类的构造函数, 子类必须在 constructor中调用父类的方法,负责会报错. 子类的 this 是父类构造出来的, 再在 ...

  2. JS - 属性描述符各配置的默认值的注意事项

    通过字面量或者obj.x = 1;创建的属性 与 通过Object.defineProperty创建的属性,他们的属性描述符的默认值是不同的,前者都为true,后者都为false.

  3. AngularJS常见面试题

    本文引自:https://segmentfault.com/a/1190000005836443 问题来源:如何衡量一个人的 AngularJS 水平? ng-if 跟 ng-show/hide 的区 ...

  4. nuxt.config有关router配置

    这里只说明一个属性,其他属性移步官方文档 https://zh.nuxtjs.org/api/configuration-router extendRoutes   官方说明: 你可以通过 exten ...

  5. 636. Exclusive Time of Functions

    // TODO: need improve!!! class Log { public: int id; bool start; int timestamp; int comp; // compasa ...

  6. Codeforces Round #460 (Div. 2): D. Substring(DAG+DP+判环)

    D. Substring time limit per test 3 seconds memory limit per test 256 megabytes input standard input ...

  7. python-9-IO编程

    1-文件读写 f = open('d:/file.txt','r') #如果文件不存在会报异常 print(f.read()) #一次性读取所有内容 f.close() 1.2 由于文件操作会用异常, ...

  8. mysql in和exists性能比较和使用【转】

    exists对外表用loop逐条查询,每次查询都会查看exists的条件语句,当 exists里的条件语句能够返回记录行时(无论记录行是的多少,只要能返回),条件就为真,返回当前loop到的这条记录, ...

  9. 十三、MySQL之IDE工具介绍及数据备份

    一.IDE工具介绍 生产环境还是推荐使用mysql命令行,但为了方便我们测试,可以使用IDE工具 下载链接:https://pan.baidu.com/s/1bpo5mqj 二.MySQL数据备份 # ...

  10. Java语言基础---两变量间的交换

    使用中间变量交换两个变量的值 int a = 10 , b = 11 , m; m = a; a = b; b = m; 不使用中间变量交换两个变量的值 int a = 10; int b = 11; ...