我是靠谱客的博主 刻苦大地,最近开发中收集的这篇文章主要介绍CodeForces - 231B Magic, Wizardry and Wonders,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

Description:

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 

就是说给一行数,从最后面的两个开始,倒数第二个减去倒数第一个的值放回到队尾,重复这种操作直到队中只剩一个元素时,输出其值。

 这一行数的范围是1~l;

仔细!!!观察可以发现,所有奇数和 减去 偶数和 等于最后的值d,不过这没用,重点是给定的最后的值d是在最大值与最小值之间的,最大值就是奇数项全取最大值,偶数项全取最小值后的差,最小值是奇数项全取最小值而偶数项全取最大值的差(前面减后面),如果d在这个范围内,那一定能找到,否则直接输出-1,判断了一定能找到后,就是枚举的过程,最大的减一减,最小的加一加,寻找满足条件的数。

AC代码:

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdlib.h>
#include<queue>
#include<map>
#include<vector>
#include<math.h>
const int INF = 0x3f3f3f3f;
using namespace std;
typedef long long ll;
typedef double ld;
const int N=110;
int main()
{
int n,d,L,a[N],b[N],m1,m2;
while(~scanf("%d%d%d",&n,&d,&L))
{
if(n%2)//奇偶项的个数
{
m1=n/2+1;
m2=n/2;
}
else m1=m2=n/2;
for(int i=0;i<m1;++i) //奇数项全取最大值
a[i]=L;
for(int i=0;i<m2;++i)//偶数项全取最小值
b[i]=1;
int d1=L*m1-1*m2;//求范围
int d2=1*m1-L*m2;
if(d>d1 || d<d2 )//不在范围
{
printf("-1n");
return 0;
}
for(int i=0;i<m1;i++)//初始化全部项,准备加加减减
a[i]=L;
for(int i=0;i<m2;i++)
b[i]=1;
int p=0;
d1=L*m1;
d2=1*m2;
while(1)
{
if(d1-d2 == d) break;
while(a[p]==1) p++;
if(p==m1) break;
a[p]--;
d1--;
}
if(p==m1)
{
p=0;
while(1)
{
if(d1-d2 == d ) break;
while(b[p]==L) p++;
if(p==m2) break;
b[p]++;
d2++;
}
}
int i;
for(i=0;i<m2;++i)
printf("%d %d ",a[i],b[i]);//奇偶相间输出
if(m1>m2)
printf("%d",a[i]);
printf("n");
}
}

 

最后

以上就是刻苦大地为你收集整理的CodeForces - 231B Magic, Wizardry and Wonders的全部内容,希望文章能够帮你解决CodeForces - 231B Magic, Wizardry and Wonders所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(39)

评论列表共有 0 条评论

立即
投稿
返回
顶部