Codeforces Round #143 (Div. 2) (ABCD 思维场)

Note

In the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn’t enough, so the friends won’t take it.

In the second sample the friends will only implement the second problem, as Vasya and Tonya are sure about the solution.

懒得说

#include <cstdio>#include <cstring>#include <algorithm>using namespace std;int a[1005][10];int main(){int n, ans = 0;scanf("%d", &n);for(int i = 0; i < n; i++){int cnt = 0;for(int j = 0; j < 3; j++){scanf("%d", &a[i][j]);if(a[i][j])cnt ++;}if(cnt >= 2)ans ++;}printf("%d\n", ans);}

B. Magic, Wizardry and Wonders

time limit per test:2 seconds

memory limit per test:256 megabytes

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.

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

题目大意:n个数字,要求得到d分,每个数字最大为l,规则是拿倒数第二个数减去最后一个数得到一个新的数放到最后,以此类推直到只剩一个数,这个数就是最后得分,现在要构造这个初始的数字序列

题目分析:假设n为5,d=a1- (a2-(a3-(a4-a5)))化简即d=a1-a2+a3-a4+a5,从第一个数开始一加一减,我们可以通过一直移项尽量使这个等式成立

d1=a1-d =a2-a3+a4-a5 若d大于0,a1取最大即l,若d1小于0,a1取最小值即1 (以下d的取值规则相同)

d2=a2-d1=a3-a4+a5

d3=a3-d2=a4-a5

d4=a4-d3=a5

这样就可以啦,最后的a5=d4

因为a是有范围的,如果最后的a值在范围之外则不可能,因为我们选数的宗旨就是让两边尽可能相等

你说只有有缘人才可以取下,我看着你手中的戒指,

Codeforces Round #143 (Div. 2) (ABCD 思维场)

相关文章:

你感兴趣的文章:

标签云: