CodeForces 667div3 C.Yet Another Array Restoration

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 0) 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 a1<a2<…<an), differences between all adjacent (consecutive) elements are equal (i.e. 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(a1,a2,…,an).

You have to answer t independent test cases.

Input
The first line of the input contains one integer t (1≤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≤n≤50; 1≤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 a1,a2,…,an (1≤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.

Example
Input
5
2 1 49
5 20 50
6 20 50
5 3 8
9 13 22
Output
1 49
20 40 30 50 10
26 32 20 38 44 50
8 23 18 13 3
1 10 13 4 19 22 25 16 7

题意:给出n,x,y三个整数 ,要求让你构造一个长度为n的数组,保证排序后相邻两个数差值唯一,并且数组中含有x ,y

思路:x,y是固定的,按照题意需要构造一个等差数列,那么首先要保证x到y这一段,暴力枚举最小的差值,使得x到y之间的数个数 <= n , 少的从x 减去差值开始补 ,再从y 加差值开始补,直到有n个数为止。

#include <bits/stdc++.h>

using namespace std;


int main(){
    int t;
    cin >> t;

    while(t --){
        int n , x , y;
        cin >> n >> x >> y;

        int k = 0;
        
        for(int i = 1;i <= 1e9;i ++){
            if((y - x) % i == 0 && (y - x) / i + 1 <= n){
                k = i;
                break;
            }
        }

        for(int i = x;i <= y;i += k){
            cout << i << ' ';
            -- n;
        }
        
        while(n && x - k >= 1){
            x -= k;
            cout << x << ' ';
            -- n;
        }
        
        while(n){
            -- n;
            y += k;
            cout << y << ' ';
        }

        cout << '\n';
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值