题解
1.如果两个障碍物之间的助跑距离不足,那么这两个障碍物只能一次跳过去
2.由于可以自由选择跳跃距离,所以我们可以在第一个障碍物之前起跳,最后一个障碍物之后落地,这样留给助跑的距离就会多
3.小细节注意一下
code
#include<bits/stdc++.h>
#define ll long long
using namespace std;
struct op
{
ll id,len;
};
ll a[200005];
void solve()
{
ll n,m,s,d;
cin>>n>>m>>s>>d;
for(ll i=1;i<=n;i++) cin>>a[i];
sort(a+1,a+1+n);
if(a[1]-1<s)
{
puts("IMPOSSIBLE");
return;
}
ll it=1;
ll maxs=2;
vector<op> ans;
ans.push_back({2,a[1]-1});
for(ll i=2;i<=n;i++)
{
if(a[i]-a[i-1]>=s+2)
{
ans.push_back({1,a[i-1]-a[it]+2});
ans.push_back({2,a[i]-a[i-1]-2});
it=i;
}
maxs=max(maxs,a[i]-a[it]+2);
}
ans.push_back({1,a[n]-a[it]+2});
if(a[n]+1<m) ans.push_back({2,m-a[n]-1});
if(maxs>d)
{
puts("IMPOSSIBLE");
return;
}
for(ll i=0;i<ans.size();i++)
{
if(ans[i].id==1) cout<<"JUMP ";
else cout<<"RUN ";
cout<<ans[i].len<<"\n";
}
}
int main()
{
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
ll t=1;
//cin>>t;
while(t--) solve();
return 0;
}
标签:障碍物,return,ll,Obstacles,back,Running,ans,push
From: https://www.cnblogs.com/pure4knowledge/p/18293537