VK Cup 2016 - Qualification Round 1 (Russian-Speaking Only, for VK Cup teams) D. Running with Obstacles 贪心
D. Running with Obstacles
题目连接:
http://www.codeforces.com/contest/637/problem/D
Description
A sportsman starts from point xstart = 0 and runs to point with coordinate xfinish = m (on a straight line). Also, the sportsman can jump — to jump, he should first take a run of length of not less than s meters (in this case for these s meters his path should have no obstacles), and after that he can jump over a length of not more than d meters. Running and jumping is permitted only in the direction from left to right. He can start andfinish a jump only at the points with integer coordinates in which there are no obstacles. To overcome some obstacle, it is necessary to land at a point which is strictly to the right of this obstacle.
On the way of an athlete are n obstacles at coordinates x1, x2, ..., xn. He cannot go over the obstacles, he can only jump over them. Your task is to determine whether the athlete will be able to get to the finish point.
Input
The first line of the input containsd four integers n, m, s and d (1 ≤ n ≤ 200 000, 2 ≤ m ≤ 109, 1 ≤ s, d ≤ 109) — the number of obstacles on the runner's way, the coordinate of the finishing point, the length of running before the jump and the maximum length of the jump, correspondingly.
The second line contains a sequence of n integers a1, a2, ..., an (1 ≤ ai ≤ m - 1) — the coordinates of the obstacles. It is guaranteed that the starting and finishing point have no obstacles, also no point can have more than one obstacle, The coordinates of the obstacles are given in an arbitrary order.
Output
If the runner cannot reach the finishing point, print in the first line of the output "IMPOSSIBLE" (without the quotes).
If the athlete can get from start to finish, print any way to do this in the following format:
print a line of form "RUN X>" (where "X" should be a positive integer), if the athlete should run for "X" more meters;
print a line of form "JUMP Y" (where "Y" should be a positive integer), if the sportsman starts a jump and should remain in air for "Y" more meters.
All commands "RUN" and "JUMP" should strictly alternate, starting with "RUN", besides, they should be printed chronologically. It is not allowed to jump over the finishing point but it is allowed to land there after a jump. The athlete should stop as soon as he reaches finish.
Sample Input
3 10 1 3
3 4 7
Sample Output
RUN 2
JUMP 3
RUN 1
JUMP 2
RUN 2
Hint
题意
有一个m长的跑道,上面有n个障碍
你每次跳最多跳d米,然后每次跳之前,需要至少跑s米
让你输出一种方案,使得这个人能够跑完全程。
题解:
直接贪心就好了。
肯定跑的多,跳的少最好。
能跳就跳,如果不满足跳的需求,就考虑下一个。
注意一下一次跳过两个栏杆这种情况
注意最后一个栏杆之后就是终点的情况。
然后就没了。
代码
#include<bits/stdc++.h>
using namespace std;
const int maxn = 4e5+7;
int a[maxn],n,m,s,d,flag[maxn],dis[maxn],tot;
bool solve()
{
if(a[1]<=s)return false;
int now = a[1]-1;
flag[tot]=0,dis[tot]=now,tot++;
for(int i=1;i<n;i++)
{
if(a[i+1]-a[i]<=s+1)continue;
if(a[i]+1-now>d)return false;
flag[tot]=1,dis[tot]=a[i]+1-now,tot++;
flag[tot]=0,dis[tot]=a[i+1]-a[i]-2,tot++;
now=a[i+1]-1;
}
if(a[n]+1-now>d)return false;
flag[tot]=1,dis[tot]=a[n]+1-now,tot++;
if(a[n]+1!=m)
flag[tot]=0,dis[tot]=m-a[n]-1,tot++;
for(int i=0;i<tot;i++)
{
if(flag[i])printf("JUMP ");
else printf("RUN ");
printf("%d\n",dis[i]);
}
return true;
}
int main()
{
scanf("%d%d%d%d",&n,&m,&s,&d);
for(int i=1;i<=n;i++)scanf("%d",&a[i]);
sort(a+1,a+1+n);
if(!solve())return puts("IMPOSSIBLE"),0;
}
VK Cup 2016 - Qualification Round 1 (Russian-Speaking Only, for VK Cup teams) D. Running with Obstacles 贪心的更多相关文章
- VK Cup 2016 - Qualification Round 2 B. Making Genome in Berland
今天在codeforces上面做到一道题:http://codeforces.com/contest/638/problem/B 题目大意是:给定n个字符串,找到最短的字符串S使得n个字符串都是这个字 ...
- VK Cup 2016 - Qualification Round 2 D. Three-dimensional Turtle Super Computer 暴力
D. Three-dimensional Turtle Super Computer 题目连接: http://www.codeforces.com/contest/638/problem/D Des ...
- VK Cup 2016 - Qualification Round 2 C. Road Improvement dfs
C. Road Improvement 题目连接: http://www.codeforces.com/contest/638/problem/C Description In Berland the ...
- VK Cup 2016 - Qualification Round 2 B. Making Genome in Berland 水题
B. Making Genome in Berland 题目连接: http://www.codeforces.com/contest/638/problem/B Description Berlan ...
- VK Cup 2016 - Qualification Round 2 A. Home Numbers 水题
A. Home Numbers 题目连接: http://www.codeforces.com/contest/638/problem/A Description The main street of ...
- VK Cup 2016 - Qualification Round 1 (Russian-Speaking Only, for VK Cup teams) C. Promocodes with Mistakes 水题
C. Promocodes with Mistakes 题目连接: http://www.codeforces.com/contest/637/problem/C Description During ...
- VK Cup 2016 - Qualification Round 1 (Russian-Speaking Only, for VK Cup teams) B. Chat Order 水题
B. Chat Order 题目连接: http://www.codeforces.com/contest/637/problem/B Description Polycarp is a big lo ...
- VK Cup 2016 - Qualification Round 1 (Russian-Speaking Only, for VK Cup teams) A. Voting for Photos 水题
A. Voting for Photos 题目连接: http://www.codeforces.com/contest/637/problem/A Description After celebra ...
- VK Cup 2016 - Qualification Round 1——A. Voting for Photos(queue+map)
A. Voting for Photos time limit per test 1 second memory limit per test 256 megabytes input standard ...
随机推荐
- 17 - 路径操作-shutil模块
目录 1 路径操作 1.1 os.path模块 1.2 pathlib模块 1.2.1 目录操作 1.2.2 文件操作 1.3 os 模块 2 shutil模块 2.1 copy复制 2.2 rm删除 ...
- 004ICMP-type对应表
一次在某个防火墙配置策略里看到如下的代码: iptables -A INPUT -p icmp --icmp-type 8 -j ACCEPT iptables -A FORWARD -p icmp ...
- tomcat打开gzip、配置utf-8
在部署描述文件中配置如下内容:(web.xml) 打开gzip compression="on"配置utf-8 URIEncoding="UTF-8" < ...
- csu 1114平方根大搜索(JAVA大小数+二分)
1114: 平方根大搜索 Time Limit: 5 Sec Memory Limit: 128 MBSubmit: 182 Solved: 96[Submit][Status][Web Boar ...
- 高屋建瓴之WebMail攻与防
0x01:前言 随着互联网的快速发展,我们的生活与互联网的联系愈加的紧密.各种快捷方便的信息化通信工具渐渐取代了传统的通信方式.微博.QQ.MSN.微信.陌陌, …这样的社交软件和平台已经成为了我们生 ...
- 亲手安装RabbitMq 3.7.2 并安装Trace插件
===============================================================================================1.安装E ...
- MVC 之AjaxHelper
http://www.cnblogs.com/jyan/archive/2012/07/23/2604958.html 除了传统的Ajax方法之外,MVC提供了AjaxHelper类: Helper ...
- iOS控制器与视图加载方法
转载记录, 请看原文: 1. iOS中的各种加载方法(initWithNibName,loadNibNamed,initWithCoder,awakeFromNib等等)简单使用 http://w ...
- [实战]MVC5+EF6+MySql企业网盘实战(7)——文件上传
写在前面 周末了,在家继续折腾网盘,今天实现网盘文件的上传. 系列文章 [EF]vs15+ef6+mysql code first方式 [实战]MVC5+EF6+MySql企业网盘实战(1) [实战] ...
- [转]基于Protel DXP软件的PCB高级编辑技巧大全
来源:基于Protel DXP软件的PCB高级编辑技巧大全 一.放置坐标指示 放置坐标指示可以显示出PCB板上任何一点的坐标位置. 启用放置坐标的方法如下:从主菜单中执行命令 Place/Coordi ...