codeforces day2 1409c

题目:

C. Yet Another Array Restoration

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

We have a secret array. You don't know this array and you have to restore it. However, you know some facts about this array:

  • The array consists of 𝑛n distinct positive (greater than 00) integers. 
  • The array contains two elements 𝑥x and 𝑦y (these elements are known for you) such that 𝑥<𝑦x<y. 
  • If you sort the array in increasing order (such that 𝑎1<𝑎2<…<𝑎𝑛a1<a2<…<an), differences between all adjacent (consecutive) elements are equal (i.e. 𝑎2−𝑎1=𝑎3−𝑎2=…=𝑎𝑛−𝑎𝑛−1)a2−a1=a3−a2=…=an−an−1). 

It can be proven that such an array always exists under the constraints given below.

Among all possible arrays that satisfy the given conditions, we ask you to restore one which has the minimum possible maximum element. In other words, you have to minimize max(𝑎1,𝑎2,…,𝑎𝑛)max(a1,a2,…,an).

You have to answer 𝑡t independent test cases.

Input

The first line of the input contains one integer 𝑡t (1≤𝑡≤1001≤t≤100) — the number of test cases. Then 𝑡t test cases follow.

The only line of the test case contains three integers 𝑛n, 𝑥x and 𝑦y (2≤𝑛≤502≤n≤50; 1≤𝑥<𝑦≤501≤x<y≤50) — the length of the array and two elements that are present in the array, respectively.

Output

For each test case, print the answer: 𝑛n integers 𝑎1,𝑎2,…,𝑎𝑛a1,a2,…,an (1≤𝑎𝑖≤1091≤ai≤109), where 𝑎𝑖ai is the 𝑖i-th element of the required array. If there are several answers, you can print any (it also means that the order of elements doesn't matter).

It can be proven that such an array always exists under the given constraints.

解析:

a2−𝑎1=𝑎3−𝑎2=…=𝑎𝑛−𝑎𝑛−1)a2−a1=a3−a2=…=an−an−1). ---->等差数列

给出数组的长度,以及两个元素x,y且(2≤𝑛≤50; 1≤𝑥<𝑦≤50),输出该数组最小可能的最大元素的一个数组,y和x的差值就是公差的一个公倍数,找到可以符合条件的最小的公差,得满足y-x<=(n-1)*d1,找出公差之后第一项a1也就等于y-(n-1)*d1。

#include<iostream>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while (t--)
    {
        int x,y,d,n,d1;
        cin>>n>>x>>y;
        d=y-x;
        for (int i=1; i<=d; i++)//
        {
            if (d%i==0)//可能的公差
            {
                d1=i;
                if (y - (n - 1)*i <= x)//y-x<=(n-1)*i求出符合想寻找的最小的公差
                {
                    break;
                }
            }
        }
        int start = y - (n - 1)*d1;
            while (start <= 0)
            {
                start += d1;
            }
            for (int i = 0; i<n; i++)
            {
                cout<< start + (d1*i)<<" ";//an=a1+nd;
            }
        cout<<endl;
        
    }
        return 0;
}
 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值