C. Yet Another Array Restoration

https://codeforces.com/contest/1409/problem/C


思路:开始的时候发现数字都在50以内,然后发现其实最大的数字就是50,不会超过50。因为n再怎么样让间距为1总能放好。

然后贪心去想x和y中间最多放多少个,开始想了gcd和整除什么的,发现样例没过。然后发现只有50,那直接从小到大枚举x~y之间的间距,看看最多能放几个数就好了。

然后再把剩下的数从 x往前放,多了再从y往后放。

#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=80;
typedef long long LL;
LL n,x,y;
LL mid=0;
LL solve()
{	
	for(LL cnt=1;cnt<=50;cnt++)
	{
		for(LL i=0;i<=n-2;i++)//枚举中间最多能放多少个点
		{
			if((i+1)*cnt==abs(y-x))
			{
				mid=i;
				return cnt;
			}	
		}	
	}	 
}
int main(void)
{
  cin.tie(0);std::ios::sync_with_stdio(false);
  LL t;cin>>t;
  while(t--)
  {
  	cin>>n>>x>>y;
  	if(n==2)
  	{
  		cout<<x<<" "<<y<<endl;	
	}
	else
	{		
  		LL cnt=solve();//差值 
  	//	debug(cnt);
  		LL res=n-2-mid;//剩下的点
		LL pre=x;
		while(res>0&&pre>=1)
		{
			res--;
			if(pre-cnt>0) pre-=cnt;	
			else break;
		} 
		for(LL i=0;i<n;i++)
		{
			cout<<pre+i*cnt<<" ";
		}
		cout<<endl;
	}
  } 
return 0;
}

猜你喜欢

转载自blog.csdn.net/zstuyyyyccccbbbb/article/details/108421090
今日推荐