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 贪心的更多相关文章

  1. VK Cup 2016 - Qualification Round 2 B. Making Genome in Berland

    今天在codeforces上面做到一道题:http://codeforces.com/contest/638/problem/B 题目大意是:给定n个字符串,找到最短的字符串S使得n个字符串都是这个字 ...

  2. 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 ...

  3. 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 ...

  4. 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 ...

  5. 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 ...

  6. 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 ...

  7. 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 ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. 可能是是最全的Springboot基础视频分享,告别无视频可学

    一头扎进SpringBoot视频教程 SpringBoot入门 2017年-张志君老师-SpringBoot(新增) 欢迎关注我的微信公众号:"Java面试通关手册" 回复关键字& ...

  2. php 全文搜索解决方法

    全套解决方案 xunsearch 一.安装编译工具 yum install make gcc g++ gcc-c++ libtool autoconf automake imake mysql-dev ...

  3. SpringBoot微服务

    在企业级软件的架构模型上,我们主要讨论下SOA与微服务架构. SOA的全称是Service-Oriented Architecture,可译为“面向服务的架构”,它是一个组件模型,将应用程序的不同功能 ...

  4. Hadoop(一):概述

    一.Hadoop是什么? Hadoop是一个由Apache基金会所开发的分布式系统基础架构.Hadoop框架最核心的设计包含两个方面,一是分布式文件系统(Hadoop Distributed File ...

  5. jekyll简单使用

    jekyll build # => 当前文件夹中的内容将会生成到 ./site 文件夹中. jekyll build –destination <destination> # =&g ...

  6. flask-login 学习(1)

    今天的目标,就是学习 flask-login.争取用1天时间,掌握个大概. 第一步:掌握flask-login的大致使用,具体参考了:https://www.centos.bz/2017/09/fla ...

  7. 洛谷 P1652圆 题解

    题目传送门 这道题也就是考你对几何的了解: 圆与圆没有公共点且一个圆在另一个圆外面时,叫做圆与圆相离. 当圆心距大于两圆半径之和时,称为两圆外离: 当圆心距小于两圆半径之差的绝对值时,称为两圆内含. ...

  8. 如何去除decimal后面的零?

    如何去除decimal后面的零? 1.260000m.ToString("G29") 不显示科学记数法? decimal.Parse("0.0000001",S ...

  9. jquery重置

    在使用jquery时要先引用 <script type="text/javascript" src="/Themes/Default/Js/jquery-1.11. ...

  10. Nodejs 接收RabbitMQ消息

    参考官方地址:https://www.rabbitmq.com/tutorials/tutorial-one-javascript.html 关于C#消息发送端,请参考<c# RabbitMQ ...