题目大意:有$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. phonegap二维码扫描插件

    原文出处:http://rensanning.iteye.com/blog/2034026 谈谈我使用这个的体会吧; git地址 https://github.com/wildabeast/Barco ...

  2. 转:mysql远程连接 Host * is not allowed to connect to this MySQL server

    在本机登入mysql后,更改"mysql"数据库里的"user"表里的"host"项,从"localhost"改为'%' ...

  3. python 一些基础知识

    Python 注释的原理: 原理:根据对象的引用计数器,对象创建会给对象一个引用计数器属性.如果该属性的值为0,那么该对象会被释放.创建一个字符串对象,但是没有任何引用,计数器为0. Python小整 ...

  4. C++ Primer 学习笔记_Chapter4 数组和指针–指针

    一.什么是指针? 指针与迭代器一样,指针提供对其所指对象的间接访问,指针保存的是另一个对象的地址: string s("hello"); string *ps = &s; ...

  5. python scrapy 实战简书网站保存数据到mysql

    1:创建项目 2:创建爬虫 3:编写start.py文件用于运行爬虫程序 # -*- coding:utf-8 -*- #作者: baikai #创建时间: 2018/12/14 14:09 #文件: ...

  6. Codeforces Round #392 (Div. 2) Unfair Poll

    C. Unfair Poll time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  7. C语言进阶——struct和union分析10

    struct的小秘密: C语言中的struct可以看作变量的集合 struct的问题:空结构体占用多大内存呢? 程序实例1: #include <stdio.h> struct TS { ...

  8. U2

    android的XML文件(包括layout下的和values下的)注释一般采用 <!--注释内容 -->的方式进行,也就是说,采用//是行不通的,不信你可以试试看.     在XML中, ...

  9. 绑定host域名 修改手机hosts域名

    windows: C:\Windows\System32\drivers\etc\hosts # 在这儿输入你需要绑定的 hosts 116.31.72.421129 bro-user.flyme.c ...

  10. 将list中的元素按照属性分类成树状的map

    技术交流群: 233513714 public LinkedHashMap<String, List<TPhoneModel>> queryPhoneList(List< ...