题目链接
题意:给你三个数 n , k , s n,k,s n,k,s,让你构造一个长度为k的数列,使得相邻两项差值的绝对值之和为 s s s,
i = 1 n a [ i ] a [ i 1 ] a [ 0 ] = 1 \sum_{i=1}^n|a[i]-a[i-1]|,a[0]=1 i=1na[i]a[i1]a[0]=1
思路:遍历每一步,找到当前能走的步数的最大可能,然后走就好了。

写这个博客是因为看cf的时候,有个远古题没补。。好像是去年暑假的题了。。今天翻出来补了一下,发现现在的思路明显比当时清晰,好像真的进步了一点点,雾,要加油!!

#include<bits/stdc++.h>

#define LL long long
#define fi first
#define se second
#define mp make_pair
#define pb push_back

using namespace std;

LL gcd(LL a,LL b){return b?gcd(b,a%b):a;}
LL lcm(LL a,LL b){return a/gcd(a,b)*b;}
LL powmod(LL a,LL b,LL MOD){LL ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}

LL n,k,s;
int main(){
	ios::sync_with_stdio(false);
	cin>>n>>k>>s;
	LL sum=0,pre=1;
	if((k*(n-1))<s||k>s)return cout<<"NO\n",0;
	cout<<"YES\n";
	for(int i=1;i<=k;i++){
		LL need=s-sum-(k-i);
		need=min(need,n);
		need=min(need,max(pre-1,n-pre));
		if(need+pre<=n)pre+=need,cout<<pre<<' ';
		else pre-=need,cout<<pre<<' ';
		sum+=need;
	}
	return 0;
}