bzoj2093 Frog
思路
非常有趣的一道题。
先考虑如何找出第K远的位置。
因为给出的序列是单调的,所以对于位置\(i\)的前\(K\)远位置肯定是一个包含位置\(i\)的长度为\(k+1\)的区间。我们用\(l\)表示这个区间的左端点,\(r\)表示这个区间的右端点。那么当\(i+1\)时,\(l\)和\(r\)都只会往右挪。而且往右挪的条件是第\(r+1\)个点与\(i+1\)的距离比第\(l\)个点与第\(i+1\)个点的距离小。
这样就可以找出每个位置的第k远位置。然后就得到了一个置换。
跳\(m\)次也就相当于把这个置换循环\(m\)次。依据倍增的思想只要\(nlogm\)的复杂度就可以完成了。
代码
#include<cstdio>
#include<iostream>
using namespace std;
typedef long long ll;
const int N = 1000000 + 100;
ll read() {
ll x = 0,f = 1;
char c = getchar();
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c <= '9' && c >= '0') {
x = x * 10 + c - '0';
c = getchar();
}
return x * f;
}
ll a[N];
int b[N],n,k;
ll m;
int tmp[N],c[N];
void calc() {
for(int i = 1;i <= n;++i) c[i] = tmp[i];
for(int i = 1;i <= n;++i) tmp[i] = c[tmp[i]];
}
int main() {
n = read(),k = read(),m = read();\
for(int i = 1;i <= n;++i) a[i] = read();
int l = 1,r = min(k + 1,n);
for(int i = 1;i <= n;++i) {
while((l < i && r < n && a[r + 1] - a[i] < a[i] - a[l]) || r < i) {
++l;++r;
}
if(a[i] - a[l] >= a[r] - a[i]) tmp[i] = l;
else tmp[i] = r;
b[i] = i;
}
for(;m;m >>= 1,calc()) {
if(m & 1) for(int i = 1;i <= n;++i) b[i] = tmp[b[i]];
}
for(int i = 1;i <= n;++i)
printf("%d ",b[i]);
return 0;
}
bzoj2093 Frog的更多相关文章
- bzoj2093: [Poi2010]Frog(单调队列,倍增)
2093: [Poi2010]Frog Time Limit: 10 Sec Memory Limit: 259 MBSubmit: 568 Solved: 186[Submit][Status] ...
- BZOJ2093 : [Poi2010]Frog
从左往右维护两个指针l,r表示离i最近的k个点的区间,预处理出每个点出发的后继,然后倍增. #include<cstdio> typedef long long ll; const int ...
- [LeetCode] Frog Jump 青蛙过河
A frog is crossing a river. The river is divided into x units and at each unit there may or may not ...
- hdu5037 Frog (贪心)
http://acm.hdu.edu.cn/showproblem.php?pid=5037 网络赛 北京 比较难的题 Frog Time Limit: 3000/1500 MS (Java/Othe ...
- CF #305 (Div. 2) C. Mike and Frog(扩展欧几里得&&当然暴力is also no problem)
C. Mike and Frog time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- Frog Jump
A frog is crossing a river. The river is divided into x units and at each unit there may or may not ...
- POJ 1054 The Troublesome Frog
The Troublesome Frog Time Limit: 5000MS Memory Limit: 100000K Total Submissions: 9581 Accepted: 2883 ...
- Leetcode: Frog Jump
A frog is crossing a river. The river is divided into x units and at each unit there may or may not ...
- hdu 4004 The Frog's Games
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4004 The annual Games in frogs' kingdom started again ...
随机推荐
- 将静态页面部署到github.io
背景: 我的腾讯云服务器是之前利用学生身份(有优惠)买的,现在快到期了,而且服务器上面只有一个引导页(静态页面)还有用,别的项目都没有用了.所以就想找一种不花钱买服务器就可以访问到我的引导页的方法 ...
- 用CSS绘制实体三角形
用CSS绘制实体三角形 使用CSS盒模型中的border(边框)即可实现如下所示的三角形: .box { width: 0; height: 0; border-width: 100px; borde ...
- 如何使用pm2一键部署node应用
准备工作 准备一台linux服务器(本文档以阿里centos为例) 安装nodejs.git.pm2等环境 项目代码 本地已经安装用于连接 Linux 实例的工具,如 Xshell 基本流程 前两步传 ...
- oracle学习笔记(十) 查询练习(一)
查询练习一 表创建 create table employee as select * from soctt.emp ; --记得授权 sysdba用户登录 grant select on scott ...
- MySQL 联表查询
关系型数据库,免不了表之间存在各种引用与关联.这些关联是通过主键与外键搭配来形成的.所以,取数据时,很大情况下单张表无法满足需求,额外的数据则需要将其他表加入到查询中来,这便是 JOIN 关键字完成的 ...
- PHP作用域和文件夹操作
1.作用域 1.1变量作用域 1.全局变量:在函数外面 2.局部变量:在函数里面,默认情况下,函数内部是不会访问函数外部的变量 3.超全局变量:可以在函数内 ...
- CSS语法规范一
CSS语法规范 CSS规则由两个主要的部分构成:选择器以及一条或多条声明. p{ color: red; font-size: 12px; } CSS代码风格 样式格式书写 紧凑格式 h3 {colo ...
- uni-app聊天室|vue+uniapp仿微信聊天实例|uniapp仿微信App界面
一.介绍 运用UniApp+Vue+Vuex+swiper+uniPop等技术开发的仿微信原生App聊天室|仿微信聊天界面实例项目uniapp-chatroom,实现了发送图文消息.表情(gif图), ...
- tomcat配置通过域名访问项目
tomcat配置通过域名访问项目,是修改conf/server.xml里面的配置信息实现.具体如下: (1)修改Connector节点的port属性值 <Connector port=" ...
- 【微信小程序】安装EsayWechat简化微信小程序的开发
1.安装easywechat composer require "overtrue/laravel-wechat" 2.文档 EasyWhchat官方文档