Codeforces Round #598 (Div. 3)C.Platforms Jumping

Codeforces Round #598 (Div. 3)C.Platforms Jumping

http://codeforces.com/contest/1256/problem/C

题意:要从0到n+1这个点,中途有m块踏板,可以改变踏板的位置但不能改变相对位置,主人公可以移动的距离是[1,d],问如何到达,或者不能到达

做法:尽可能的扩大主人公所能到达的,即最远距离,如果最远距离都不符合要求,那么肯定就无法到达,如果最远距离超过了目的地,就将踏板尽可能的往前移

AC代码

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<queue>
#include<map>
#define ll long long
#define pb push_back
#define rep(x,a,b) for (int x=a;x<=b;x++)
#define repp(x,a,b) for (int x=a;x<b;x++)
#define W(x) printf("%d\n",x)
#define WW(x) printf("%lld\n",x)
#define pi 3.14159265358979323846
#define mem(a,x) memset(a,x,sizeof a)
#define lson rt<<1,l,mid
#define rson rt<<1|1,mid+1,r
using namespace std;
const int maxn=2e6+7;
const int INF=1e9;
const ll INFF=1e18;
int a[maxn],ans[maxn];
int main()
{
    int n,m,d,now=0;
    scanf("%d%d%d",&n,&m,&d);
    rep(i,1,m)scanf("%d",&a[i]);
    rep(i,1,m)
    {
        for (int j=d;j<=a[i]+d-1;j++)
            ans[now+j]=i;//将每一块踏板都标上记号方便输出
        now+=a[i]+d-1;
    }
    //now记录的是主人公能运动的最远距离
    if (now+d<n+1)//无法到达的情况
    {
        cout<<"NO"<<endl;
    }
    else if (now>n)//超出目的地的情况,利用vector将踏板往前移
    {
        int res=now-n;
        vector<int> V;
        rep(i,1,now)
        {
            if (ans[i]==0&&res)res--;
            else V.pb(ans[i]);
        }
        cout<<"YES"<<endl;
        rep(i,0,n-1)cout<<V[i]<<" ";cout<<endl;
    }
    else//其余情况直接输出
    {
        cout<<"YES"<<endl;
        rep(i,1,n)cout<<ans[i]<<" ";cout<<endl;
    }
}
发布了109 篇原创文章 · 获赞 7 · 访问量 6045

猜你喜欢

转载自blog.csdn.net/w_udixixi/article/details/102922730