题目链接:

D. Running with Obstacles

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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

Examples
input
3 10 1 3
3 4 7
output
RUN 2
JUMP 3
RUN 1
JUMP 2
RUN 2
input
2 9 2 3
6 4
output
IMPOSSIBLE

题意:n个障碍,坐标分别是啊a[i],终点是m,助跑s米才能最远跳d米,问最后是否能到达m,以及是怎样到达的;
思路:把障碍都标记看是否与上一障碍之间的距离是否够s米,不够的话就将这个与上一障碍合并,我采用一个数组标记的方法标记合并的最前面的障碍位置,再从后往前找,看跑和跳是否满足条件,是的话用ans数组记录下来,不行的话就return 0 结束;
AC代码:
#include <bits/stdc++.h>
using namespace std;
const int N=2e5+;
int a[N],dp[N],ans[*N];
int n,m,s,d;
int main()
{
scanf("%d%d%d%d",&n,&m,&s,&d);
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
}
sort(a+,a+n+);
if(a[]->=s)dp[]=;
else dp[]=;
for(int i=;i<=n;i++)
{
if(a[i]-a[i-]->=s)dp[i]=i;
else dp[i]=dp[i-];
}
/*for(int i=1;i<=n;i++)
{
cout<<dp[i]<<"#"<<endl;
}*/
int pos=,flag=,cnt=;
stack<int>st;
for(int i=n;i>; )
{
if(dp[i]==i)
{
st.push(a[i]+);
st.push(a[i]-);
i--;
}
else
{
st.push(a[i]+);
i=dp[i];
st.push(a[i]-);
i--;
}
}
while(!st.empty())
{
int x=st.top();
st.pop();
if(flag)
{
if(x-pos>=s)
{
ans[cnt++]=x-pos;
pos=x;
}
else
{
cout<<"IMPOSSIBLE"<<"\n";
return ;
}
flag=;
}
else
{
if(x-pos<=d)
{
ans[cnt++]=x-pos;
pos=x;
}
else
{
cout<<"IMPOSSIBLE"<<"\n";
return ;
}
flag=;
}
}
if(a[n]!=m-)
{
ans[cnt++]=m-a[n]-;
}
for(int i=;i<cnt;i++)
{
if(i%)printf("RUN %d\n",ans[i]);
else printf("JUMP %d\n",ans[i]);
}
return ;
}

codeforces 637D D. Running with Obstacles(dp,水题,贪心)的更多相关文章

  1. Codeforces Round #303 (Div. 2) D. Queue 水题贪心

    题目: 题意:给你n个数值,要求排列这个序列使得第k个数值的前K-1个数的和>=第k个数值的个数尽可能多: #include <iostream> #include <cstd ...

  2. Codeforces 148D 一袋老鼠 Bag of mice | 概率DP 水题

    除非特别忙,我接下来会尽可能翻译我做的每道CF题的题面! Codeforces 148D 一袋老鼠 Bag of mice | 概率DP 水题 题面 胡小兔和司公子都认为对方是垃圾. 为了决出谁才是垃 ...

  3. ACM :漫漫上学路 -DP -水题

    CSU 1772 漫漫上学路 Time Limit: 1000MS   Memory Limit: 131072KB   64bit IO Format: %lld & %llu Submit ...

  4. [poj2247] Humble Numbers (DP水题)

    DP 水题 Description A number whose only prime factors are 2,3,5 or 7 is called a humble number. The se ...

  5. codeforces Gym 100187L L. Ministry of Truth 水题

    L. Ministry of Truth Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/p ...

  6. Codeforces Round #185 (Div. 2) B. Archer 水题

    B. Archer Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/312/problem/B D ...

  7. Educational Codeforces Round 14 A. Fashion in Berland 水题

    A. Fashion in Berland 题目连接: http://www.codeforces.com/contest/691/problem/A Description According to ...

  8. Codeforces Round #360 (Div. 2) A. Opponents 水题

    A. Opponents 题目连接: http://www.codeforces.com/contest/688/problem/A Description Arya has n opponents ...

  9. Codeforces Round #190 (Div. 2) 水果俩水题

    后天考试,今天做题,我真佩服自己... 这次又只A俩水题... orz各路神犇... 话说这次模拟题挺多... 半个多小时把前面俩水题做完,然后卡C,和往常一样,题目看懂做不出来... A: 算是模拟 ...

随机推荐

  1. Android调用相机实现拍照并裁剪图片,调用手机中的相冊图片并裁剪图片

    在 Android应用中,非常多时候我们须要实现上传图片,或者直接调用手机上的拍照功能拍照处理然后直接显示并上传功能,以下将讲述调用相机拍照处理图片然后显示和调用手机相冊中的图片处理然后显示的功能,要 ...

  2. GIS开发站点收藏

    Arcgis API for Silverlight ArcGIS API for Silverlight开发入门 C#开发ArcGIS

  3. Android使用JUnit进行单元测试

    前言:为什么要进行单元测试?单元测试能快速是开发者,找到代码中的问题所在,因为是单元测试,所以代码只执行响应的测试单元,执行快解决问题的效率高,同时提高代码的质量. Android中的单元测试可简单分 ...

  4. react-native create-react-app创建项目报错SyntaxError: Unexpected end of JSON input while parsing near '...ttachment":false,"tar' npm代理

    SyntaxError: Unexpected end of JSON input while parsing near '...ttachment":false,"tar' 错误 ...

  5. ios错误ignoring file xxx missing required architecture x86_64 in file

    错误ignoring file xxx missing required architecture x86_64 in file 解决方法: 1.在Project target里“Architectu ...

  6. Eclipse搭建C++开发环境

    http://jingyan.baidu.com/article/456c463b67b4310a59314468.html

  7. Linux 技巧:让进程在后台运行的可靠方法

    原文链接:http://www.ibm.com/developerworks/cn/linux/l-cn-nohup/ 想让进程在断开连接后依然保持运行?如果该进程已经开始运行了该如何补救? 如果有大 ...

  8. java基础之【堆、栈、方法区】结构图

    |--数组实例化过程 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvaHViaWFvXzA2MTg=/font/5a6L5L2T/fontsize/400/ ...

  9. IOS连接

    http://www.wuleilei.com/blog/323 不错 http://blog.csdn.net/totogo2010/ http://blog.csdn.net/totogo2010 ...

  10. http => https 升级

    准备证书 阿里云安全(云盾)-> CA证书服务,购买证书,个人测试的话可以使用免费的,期限1年. 购买证书后,把域名与证书进行绑定,提交审核,大概10分钟左右,正常情况下审核就可以通过.证书准备 ...