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. Coursera在线学习---第三节.归一化处理(Normalize)

    一.归一化(也说标准化)作用 1)将有量纲特征转化为无量纲特征 2)能够加快收敛(主要指梯度下降法时) 二.Octave中计算          mean(A)   求解矩阵中每一列的均值 std(A ...

  2. Django框架<一>

    Django框架 Python的WEB框架有Django.Tornado.Flask 等多种,Django相较与其他WEB框架其优势为:大而全,框架本身集成了ORM.模型绑定.模板引擎.缓存.Sess ...

  3. python使用requests模块模拟登陆知乎

    from bs4 import BeautifulSoup import requests import time def captcha(captcha_data): with open(" ...

  4. How to insert a segment of noise to music file

    如何向音频文件中插入噪声 为了研究噪声和音乐对EEG的的影响,实验前需要准备一段夹杂噪声的音乐. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ...

  5. ButterKnifeZelezny简单使用教程

    https://github.com/avast/android-butterknife-zelezny     一,配置butterknife Configure your project-leve ...

  6. udev和rules使用规则

    本文以通俗的方法阐述 udev 及相关术语的概念.udev 的配置文件和规则文件,然后以 Red Hat Enterprise Server 为平台演示一些管理设备文件和查询设备信息的实例.本文会使那 ...

  7. TCP可靠传输和拥塞控制

    1.TCP的可靠传输 tcp的可靠传输主要靠 来自接收方的确认报文 和 超时重传. 发出报文,计时器开始计时,在规定超时时间内未收到确认报文则重新发送. 注意:发送报文都留一个副本,如果收到确认报文就 ...

  8. Spring MVC数据绑定(二)

    之前学习了SpringMVC数据绑定的基本知识和简单数据绑定以及POJO类型数据的绑定.接下来总结剩下的一些数据类型的绑定 1. 绑定包装POJO 所谓的包装POJO,就是在一个POJO中包含另一个简 ...

  9. day4 正则表达式(regular)

    正则(regular),要使用正则表达式需要导入Python中的re(regular正则的缩写)模块.正则表达式是对字符串的处理,我们知道,字符串中有时候包含很多我们想要提取的信息,掌握这些处理字符串 ...

  10. LR11中自定义函数web_custom_request请求

    Action() { char * ip,temp; int state; double time_elapsed, duration, waste; merc_timer_handle_t time ...