题解 P4753 【River Jumping】
模拟!!!
纯粹de模拟+一丢丢贪心(能暴踩就暴踩)!!!
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define get getchar()
int read()
{
int t=0,x=1;char ch=get;
while((ch<'0'||ch>'9')&&ch!='-')ch=get;
if(ch=='-')x=-1,ch=get;
while(ch<='9'&&ch>='0')t=t*10+ch-'0',ch=get;
return x*t;
}//快速读入(可以忽略)
int n,m,s;
int st[100011],ans[100011];//st数组表示石头的位置,ans答案数组
bool f[100011];//f[i]判断第i块石头是否被踩过
int main()
{
n=read(),m=read(),s=read();
for(int i=1;i<=m;i++)st[i]=read();//输入,没什么好港的
int pl=0,tot=1;//pl==place,表示当前位置
for( int i=1;i<=m;i++)
{
if(st[i]-pl>=s)
{
ans[tot]=i;tot++;
pl=st[i];
f[i]=1;
}
}//第一次过河
if(n-pl<s){cout<<"NO";return 0;}//若此时站的place跳不到对岸,又
//因为当前位置已经是距离对岸最近的,所以对岸也无法踩到当前石头,所以输出NO
pl=n;
ans[tot]=m+1;
tot++;//将当前位置修改为河对岸
for( int i=m;i>=1;i--)
{
if(f[i])continue;
if(pl-st[i]<s){cout<<"NO";return 0;}//这是最后一次遍历此点,若还是踩不到,则永远也踩不到
ans[tot]=i;tot++;
pl=st[i];
f[i]=1;
}//跳回来
if(pl<s){cout<<"NO";return 0;}
cout<<"YES"<<endl;
for( int i=1;i<=tot;i++)cout<<ans[i]<<' ';
}
本蒟蒻第一次发题解,请多多包涵(顶一顶身心健康)