题目链接:
题意:
有n,k,s;
n为最远的房子,k为走几次,s为可以走几步;
每次不能停留在原地;
求是否可以走k次走到s步;
思路:
先占坑;
看的别人的代码,并没有完全理解。
AC代码如下:
#include <cstdio>
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
using namespace std;
long long min(long long a,long long b)
{
if(a<b)
return a;
else
return b;
}
int main()
{
long long n,k,s,flag=1;
scanf("%lld%lld%lld",&n,&k,&s);
if(k>s||(n-1)*k<s)//不能满足
{
flag=0;
}
if(flag==0)
{
printf("NO\n\n");
}
else
{
printf("YES\n");
}
if(flag==1)
{
long long st=1,t=1;
while(k--)
{
long long small=min(n-1,s-k);
s=s-small;
if(st+small<=n)
{
st=st+small;
}
else
{
st=st-small;
}
if(t==1)
{
printf("%lld",st);
t++;
}
else
{
printf(" %lld",st);
}
}
printf("\n");
}
}