题目链接:

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 JNI开发之NDK环境搭建

    参考:http://www.cnblogs.com/yejiurui/p/3476565.html 谷歌改良了ndk的开发流程,对于Windows环境下NDK的开发,如果使用的NDK是r7之前的版本, ...

  2. python 基础 9.6 设计表结构

    一. 设计表结构    在操作设计数据库之前,我们先要设计数据库表结构,我们就来分析分析经典的学生,课程,成绩,老师这几者他们之间的关系,我们先来分析各个主体他们直接有什么属性,并确定表结构,在实际开 ...

  3. spring注解集合

    spring篇 @Autowired Spring 2.5 引入了 @Autowired 注释,它可以对类成员变量.方法及构造函数进行标注,完成自动装配的工作. Spring 通过一个 BeanPos ...

  4. Python 字符串拼接、格式化输出、深浅复制

    拼接:"+"号(同类型可拼接) >>>li = [1,2] >>>li + li [1,2,1,2] >>>li*2 [1,2 ...

  5. hdu1573(线性同余方程组)

    套模板,因为要是正整数,所以处理一下x=0的情况. X问题 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ...

  6. eclipse里面用svn关联项目

    eclipse里面共享项目经常会用到svn或者git插件 关联项目的步骤如下: 如果 点击finish会遇到卡住问题的话,不要着急,我们需要设置svn的client设置: 如果设置了之后还是很卡的话, ...

  7. 九度OJ 1256:找出两个只出现了一次的数字 (位运算)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:568 解决:186 题目描述: 一个整型数组里除了两个数字之外,其他的数字都出现了两次.请写程序找出这两个只出现一次的数字. 输入: 输入的 ...

  8. META-INF中的INF的意思

    1 META是元的意思,比如meta data,元数据. 2 什么是meta data 元数据就是描述其它数据的数据,比如web page中的meta data,包括关键字,对该网页的描述等等. 3 ...

  9. inux c编程:记录锁

    记录锁的功能:当一个进程正在读或修改文件的某个部分是,它可以阻止其他进程修改同一文件区.对于这个功能阐述我认为有三点要解释的: 记录锁不仅仅可以用来同步不同进程对同一文件的操作,还可以通过对同一文件加 ...

  10. You can also run `php --ini` inside terminal to see which files are used by PHP in CLI mode.

    [root@localhost dreamstart]# composer installLoading composer repositories with package informationI ...