codeforces 231B Magic, Wizardry and Wonders

Vasya the Great Magician and Conjurer loves all kinds of miracles and wizardry. In one wave of a magic wand he can turn an object into something else. But, as you all know, there is no better magic in the Universe than the magic of numbers. That’s why Vasya adores math and spends a lot of time turning some numbers into some other ones.

This morning he has n cards with integers lined up in front of him. Each integer is not less than 1, but not greater than l. When Vasya waves his magic wand, two rightmost cards vanish from the line and a new card magically appears in their place. It contains the difference between the left and the right numbers on the two vanished cards. Vasya was very interested to know what would happen next, and so he waved with his magic wand on and on, until the table had a single card left.

Suppose that Vasya originally had the following cards: 4, 1, 1, 3 (listed from left to right). Then after the first wave the line would be: 4, 1, -2, and after the second one: 4, 3, and after the third one the table would have a single card with number 1.

Please note that in spite of the fact that initially all the numbers on the cards were not less than 1 and not greater than l, the numbers on the appearing cards can be anything, no restrictions are imposed on them.

It is now evening. Vasya is very tired and wants to return everything back, but does not remember which cards he had in the morning. He only remembers that there were n cards, they contained integers from 1 to l, and after all magical actions he was left with a single card containing number d.

Help Vasya to recover the initial set of cards with numbers.

Input
The single line contains three space-separated integers: n (2 ≤ n ≤ 100) — the initial number of cards on the table, d (|d| ≤ 104) — the number on the card that was left on the table after all the magical actions, and l (1 ≤ l ≤ 100) — the limits for the initial integers.

Output
If Vasya is mistaken, that is, if there doesn’t exist a set that meets the requirements given in the statement, then print a single number -1, otherwise print the sought set containing n integers from 1 to l. Separate the integers by spaces. Print the integers in the order, in which they were written on the cards from left to right. If there are several suitable sets of numbers, you can print any of them.

Examples
Input

3 3 2
Output
2 1 2
Input

5 -4 3
Output
-1
Input

5 -4 4
Output

2 4 1 4 1
有一列数个数为n范围为1~l通过操作 把序列最后两位拿出用前一位减去后一位再把得到的结果放回去最后只剩一个结果k,题目给出n,l,k求该序列。
不难看出 结果就是奇数项的和-偶数项的和(可以推导出来)。
通过这个求出k的范围判断是否存在该序列。
可以通过不断的递推求差值最后得到最后一位所需要的差值,然后就可以推回来得到k了

#include<bits/stdc++.h>
#include<cmath>
#define ll long long
using namespace std;
int main()
{
    ll maxx=-1,nn=-1;
    ll n,k,a[100009],b[100009],d,l;
    memset(b,0,sizeof(b));
    cin>>n>>d>>l;
    int d1=floor(n*1.0/2),d2=ceil(n*1.0/2);
    if(d2*l-d1<d||d<d2-d1*l)
        cout<<-1<<endl;
    else
    {
        for(int i=1;i<=n;i++)
        {
            if(d>0)
            {
                a[i]=l;
                d=a[i]-d;
            }
            else
            {
                a[i]=1;
                d=a[i]-d;
            }
        }
        a[n]-=d;
        for(int i=1;i<=n;i++)
        {
            cout<<a[i]<<' ';
        }
        cout<<endl;
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值