codeforce-231B--- Magic, Wizardry and Wonders (思维+构造)

来源:互联网 发布:索尼电视推荐 知乎 编辑:程序博客网 时间:2024/06/18 12:39
B. Magic, Wizardry and Wonders
time limit per test:2 seconds
memory limit per test:256 megabytes
input:standard input
output:standard output

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 thanl. 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 thanl, 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 weren cards, they contained integers from 1 tol, and after all magical actions he was left with a single card containing numberd.

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, andl (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 containingn integers from 1 tol. 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 


题意:一个序列,每次把序列的最后两个数变成倒数第二个数减去倒数第一个数,直到序列剩下一个数停止;题目给出了序列原先的数的个数,最后的结果,以及序列中每个数的上限,要求输出原序列,任意一种,若没有这种序列输出-1;

思路:很容易发现最后的结果就是序列奇数项的和与序列偶数项的和的差,那么搜先可以判断最后的结果是否合法,不合法即输出-1,然后对于每次的结果m分3种情况,

1、m=0:此时先把奇数项和偶数项都置为1,然后看哪个的项数少,把其中第一个数变成2即可;

2、m>0:此时只有偶数项的数全部为1是奇数项才是必然有解的;

3、m<0:此时奇数项全部为1时偶数项才必然有解;

确定这3个策略后剩下的就是简单构造了~

AC代码:

#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<queue>#include<vector>#include<map>#define inf 0xfffffff#define maxn 100100#define ll  segtree[root].l#define rr  segtree[root].rusing namespace std;int n,m,k;int main(){    while(~scanf("%d%d%d",&n,&m,&k))    {        int ji=(n+1)/2;//奇数项的个数        int ou=n/2;        int mx=ji*k-ou;//确定最大值与最小值,看输入的结果是否合法        int mi=ji-ou*k;        int a[105],b[105];        if(m<mi||m>mx)        {            printf("-1\n");            continue;        }        for(int i=0;i<ji;i++)//首先把奇数项和偶数项的值都置为最小的1            a[i]=1;        for(int i=0;i<ou;i++)            b[i]=1;        if(m==0)        {                        if(ji>ou) b[0]=2;            if(ou>ji) a[0]=2;        }        else if(m<0)        {            int tmp;//此时每次把偶数项补成最大值tmp为有多少项可以补成最大值            if(k==1)                tmp=(ji-m-ou);            else                tmp=(ji-m-ou)/(k-1);            for(int i=0;i<tmp;i++)                b[i]=k;            b[tmp]+=ji-m-ou-(k-1)*tmp;        }        else        {            int tmp;            if(k==1)                tmp=ou+m-ji;            else                tmp=(ou+m-ji)/(k-1);            for(int i=0;i<tmp;i++)                a[i]=k;            a[tmp]+=ou+m-ji-(k-1)*tmp;        }        int f=max(ji,ou);        int cnt=ji+ou;        for(int i=0;i<f;i++)        {            if(cnt==1)            {                printf("%d\n",a[i]);break;            }            else                printf("%d ",a[i]),cnt--;            if(cnt==1)            {                printf("%d\n",b[i]);break;            }            else                printf("%d ",b[i]),cnt--;        }    }    return 0;}


阅读全文
0 0