C. Yet Another Array Restoration

104 篇文章 0 订阅

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;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值