C - Yet Another Array Restoration

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.
数组由n个不同的(大于0)正整数。
The array contains two elements x and y (these elements are known for you) such that x<y.
该数组包含两个元素 x 和 y (这些元素是已知的),这样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).
如果你递增去排序这个数组(像a1<a2<…<an),所有相邻(连续)元素之间的差异是相等的(就是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).
在所有可能的阵列满足给定的条件下,我们让你恢复一个最小可能性的最大的元素。换句话说,你必须减少最大值(a1,a2,…,an)。
You have to answer t independent test cases.
你必须回答 t 独立的测试用例。

Input

The first line of the input contains one integer t (1≤t≤100) — the number of test cases. Then t test cases follow.
输入的第一行包含一个整数 t (1≤t≤100) 测试用例的数量。然后遵循 t 测试用例。
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.
测试用例的唯一行包含三个整数 n , x , y (2≤n≤50; 1≤x<y≤50) ,数组的长度和分别在数组两个元素。

Output

For each test case, print the answer: n integers a1,a2,…,an (1≤ai≤10^9), 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).
对于每个测试用例,打印答案:n 整数a1, a2,…, an(1≤ai≤10^9), 其中 ai是i-th元素所需的数组。如果有几个答案,您可以打印一些(这也意味着元素的顺序并不重要)。
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

题目分析

看这个题一下子看直接翻译是看得迷迷糊糊的,机翻还是很拉跨的,所以还是得自己一个个去翻译单词联系整个题目。概括来说,就是你要在一个未知的等差数列里求一个该数列的元素最小数列,其实相当于是将最大项一直往前推,最小元素要大于0。

#include <stdio.h>
int main(){
    int t;//测试用例数量
    scanf("%d", &t);
    while (t--) {
        int n, x, y, k, d;
        scanf("%d %d %d", &n, &x, &y);//输入数组长度和数组的两个元素
        k = n - 1;//模拟y跟x之间的公差个数
        d = y - x;//模拟x跟y的公差
        while (d % k != 0) {//求出x跟y最大的公差
            k--;
        }
        d = d / k;
        if ((n - 1) * d < y) {//若公差乘最大项数大于y,就减小y的值
            y = y - (n - 1) * d;
        }
        else {//若y小就取与公差的余数
            y = y % d;
            if (y == 0) y += d;//不为零
        }
        for (int i = 0; i < n - 1; ++i) {//输出符合的数列元素
            printf("%d ", y + i * d);
        }
        printf("%d\n", y + n * d - d);
    }
    return 0;
}

这道题主要是得看懂题目,要是有更好的方法就更好了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值