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 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
Copy
3 3 2
Output
Copy
2 1 2
Input
Copy
5 -4 3
Output
Copy
-1
Input
Copy
5 -4 4
Output
Copy
2 4 1 4 1
题意:问一个魔牌 的游戏,从最右边开始,每次最右边两个做差替换,最后只剩下一个d。题目给你一个d问你可能的序列是什么,还给你一个l表示数列中最大
这个题目正解应该是模拟。每一次做差后得到的数字,都是数字右边的项 奇数项的和减去偶数项的和。所以最后的d也是有个范围(每个d都有个范围,这是将要贪心的关键),因为是奇数项的和减去偶数项的和,所以让奇数项为 最大l,偶数项最小为1,可以得到一个d的最大值,奇数项最小为1,偶数项最大为l,可以得到一个d的最小值,所以最终的d应该在最小值 与 最大值之间。
接下来将要贪心了(这个题目的贪心真是巧妙,显示了贪心的性质),最终的d介于最大与最小值之间。我们要验证这个d是够能否能够写出一个序列,不妨先确定第一个元素,若d>0,则让这个元素为最大值l,为什么呢?因为确定这个元素后 ,可以得到后边的d,让后边的d尽量在它的范围内,又因为d的范围为负 ---正,所以尽量让后边d的值接近于0.同理d<=0为1。这样只需最后检验最后一个元素d'是否符合(1 - l),就行了。
AC Code:
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<bitset>
#include<cctype>
#define LL long long
#define maxn (LL)1e5
#define INF 0x3f3f3f3f
const double eps = 0.0000001;
using namespace std;
inline int sgn(double x) {
return (x > eps) - (x < -eps);
}
#define re register
#define re register
static char buf[100000],*pa=buf,*pd=buf;
#define gc pa==pd&&(pd=(pa=buf)+fread(buf,1,100000,stdin),pa==pd)?EOF:*pa++//文件字符读入
inline int read()//整数读入
{
re int x(0),f(1);re char c(gc);
while(c>'9'||c<'0')f=c=='-'?-1:1,c=gc;
while(c>='0'&&c<='9')x=x*10+c-48,c=gc;
return f*x;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
#ifndef ONLINE_JUDGE
//freopen("input.txt","r",stdin);
#endif // ONLINE_JUDGE
LL a,b,c,sum,num;
cin>>a>>b>>c;
vector<LL> Q;
while(1)
{
if(Q.size()== a-1)
{
if(b>=1&&b<=c){
Q.push_back(b);
for(int i =0;i<Q.size();++i) cout<<Q[i]<<" ";
return 0;
}
else return cout<<-1,0;
}
if(b<=0)//把等号归于1
{
Q.push_back(1);
b = 1-b;
}
else if(b){
Q.push_back(c);
b = c-b;
}
}
}