Codeforces 637D Running with Obstacles (贪心)

原创 2016年05月31日 15:55:19

解析:查看每对相邻的障碍,如果距离大于s,那么可以落地并在下一个障碍前起跳。对每次落地和起跳加以判断即可。

[code]:

#include<cstdio>
#include<cstring>
#include<algorithm>

using namespace std;
typedef pair<int,int> P;
const int maxn = 2e5+5;

int n,m,s,d,a[maxn],top;
P ans[4*maxn];

void sol(){
    int i,j,run,jump,len;
    run = -1;jump = -1;
    for(i = 1;i <= n;i++){
        if(s+2<=a[i]-a[i-1]){
            if(jump!=-1){
                if(a[i-1]+1-jump<=d&&(top>0&&ans[top-1].first==0&&ans[top-1].second>=s))ans[top++] = P(1,a[i-1]+1-jump);
                else{
                    puts("IMPOSSIBLE");
                    return;
                }
            }
            ans[top++] = P(0,a[i]-a[i-1]-2);
            jump = a[i]-1;
        }
    }
    if(a[n]+1-jump<=d&&(top>0&&ans[top-1].first==0&&ans[top-1].second>=s)) ans[top++] = P(1,a[n]+1-jump);
    else{
        puts("IMPOSSIBLE");
        return;
    }
    if(m!=a[n]+1){
        ans[top++] = P(0,m-a[n]-1);
    }
    for(i = 0;i < top;i++){
        if(ans[i].first) printf("JUMP %d\n",ans[i].second);
        else printf("RUN %d\n",ans[i].second);
    }
}

int main(){
    int i,j;
    scanf("%d%d%d%d",&n,&m,&s,&d);
    for(i = 1;i <= n;i++) scanf("%d",&a[i]);
    sort(a+1,a+n+1);
    a[0] = -1;
    a[n+1] = m+1;
    sol();

    return 0;
}



版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

Error running app: This version of Android Studio is incompatible with the Gradle Plugin used. Try d

在开发中从代码仓库导入项目时,突然遇到个问题, 就是cline 和 Rebuile 都没有问题 ,但是一运行就报Error running app: This version of Android ...

【codeforces 732D】【二分+贪心】

传送门:D. Exams 描述: D. Exams time limit per test 1 second memory limit per test 2...

Codeforces 803D Magazine Ad【二分+贪心】

D. Magazine Ad time limit per test 1 second memory limit per test 256 megabytes input st...

Codeforces724 D. Dense Subsequence(字符串贪心)

D. Dense Subsequence time limit per test 2 seconds memory limit per test 256 megabytes input s...

codeforces - 732D Exams 【二分 + 贪心】

Exams time limit per test 1 second memory limit per test 256 megabytes input stand...

Codeforces Round #378 (Div. 2) D. Kostya the Sculptor【贪心】

D. Kostya the Sculptor time limit per test 3 seconds memory limit per test 256 megabytes input st...

Codeforces 732D Exams【贪心+二分】

D. Exams time limit per test 1 second memory limit per test 256 megabytes input standard...

【贪心】Codeforces 704B & 705D Ant Man

题目链接:   http://codeforces.com/problemset/problem/704/B 题目大意:   给N个点,起点S终点T,每个点有X,A,B,C,D,根据I和J的X...

Codeforces 3D Least Cost Bracket Sequence --- 贪心

D. Least Cost Bracket Sequence time limit per test  1 second memory limit per test  64 m...

Codeforces 553D Nudist Beach 优先队列 贪心

原题见CF 553D无向图G,n个点,m条边,k个坏点。 在G中选取子图S(可以不连通),S不能包含坏点。对于每个S中的点x,描述强度值I=x的属于S的邻居数/x的所有邻居数。I=x的属于S的邻居数...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Codeforces 637D Running with Obstacles (贪心)
举报原因:
原因补充:

(最多只允许输入30个字)