Codeforces Round #143 (Div. 2) B - Magic, Wizardry and Wonders 数学

来源:互联网 发布:青岛基督教软件下载 编辑:程序博客网 时间:2024/06/05 01:55

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.

Sample test(s)
input
3 3 2
output
2 1 2 
input
5 -4 3
output
-1
input
5 -4 4
output
2 4 1 4 1 

        题意:一个数列a1,a2,,,,,,an,其中1<ai<l,1<=i<=n。进行如下操作:从最右边开始两个数a(n-1)和a(n)取出来,a(n-1)-a(n)得到一个新的数,然后加入到原来的数列中。如此操作下去,直到最后只剩下一个数。先给出最后的数d,和数的个数n,数的最大限制l,求是否有满足的数列,并求出(任意一个)。

       分析原数列,a1,a2,,,,,,,an,  根据操作,a(n-1)-a(n)  =>  a(n-2)-( a(n-1)-a(n) )  =>  a(n-3)-( a(n-2)-( a(n-1)-a(n) ) )

 ,,,,,,最后化简得:a1-a2+a3-a4+,,,,,,an=d   =>   (a1+a3+a5...)-(a2+a4+a6...)=d   

  令a=(a1+a3+a5...)  b=(a2+a4+a6...)  ac=(n+1)/2    bc=n/2  则只要满足a>=ac   b>=bc  且  a<=ac*l    b<=bc*l    即可求出原数列。

    My code:

//STATUS:C++_AC_31MS_0KB  #include<stdio.h>#include<stdlib.h>#include<string.h>#include<algorithm>#include<string>#include<vector>#include<queue>#include<stack>#include<set>#define LL __int64#define Max(x,y) ((x)>(y)?(x):(y))#define Min(x,y) ((x)<(y)?(x):(y))#define lson l,mid,rt<<1#define rson mid+1,r,rt<<1|1#define mem(a,b) memset(a,b,sizeof(a))const int MAX=110,INF=200000000,MOD=1000000007;const double esp=1e-6;int ans[MAX];int n,d,l;int main(){//freopen("in.txt","r",stdin);    int i,j,a,b,ac,bc,t;    while(~scanf("%d%d%d",&n,&d,&l)){        ac=(n+1)>>1;        bc=n>>1;        if(d>0){            b=bc;            a=b+d;        }        else {            a=ac;            b=a-d;        }        if((double)a/ac<=l && (double)b/bc<=l){            for(i=0;i<n;i+=2)                ans[i]=a/ac;            t=a%ac;            for(i=0;i<n && t;i+=2,t--)                ans[i]++;            for(i=1;i<n;i+=2)                ans[i]=b/bc;            t=b%bc;            for(i=1;i<n && t;i+=2,t--)                ans[i]++;            printf("%d",ans[0]);            for(i=1;i<n;i++)                printf(" %d",ans[i]);            putchar('\n');        }        else printf("-1\n");    }    return 0;}

原创粉丝点击