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

原创 2016年08月28日 16:49:27

原题链接

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 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 


  用maxs[i], mins[i]表示只剩i张卡片时第i张卡片上数字的最大值和最小值,对于题中给出的n, L.可以确定maxs[n] = L,

 mins[n] = 1, 则可以推出maxs[n-1] = L - mins[n], mins[n-1] = 1 - maxs[n]以此类推,求出maxs和mins.

题中给出的d是桌上只剩一张卡片时的卡片上的数字,若d < mins[1] || d > maxs[1]则无解。

否则,a = 1 - d, b = L - d.则[a, b]和[mins[2], maxs[2]]两个区间必定有交集.

1.mins[2] <= a <= maxs[2]那么最初第一张卡牌的数字就可以确定为1,那么现在桌上有两张卡片,第二张卡片数字为1 - d.

2. mins[2] <= b <= maxs[2]那么最初第一张卡牌的数字就可以确定为l,那么现在桌上有两张卡片,第二张卡片数字为L- d.

上述两步只要执行满足条件的一步就行,不断重复上述步骤,从而求出第2, 3, 4, ..n张卡牌原来上的数字.

#include <bits/stdc++.h>
#define maxn 105

using namespace std;
typedef long long ll;

int maxs[maxn], mins[maxn], ans[maxn];
int main(){
	
	int n, d, l;
	
	scanf("%d%d%d", &n, &d, &l);
	mins[0] = 1;
	maxs[0] = l;
	for(int i = 1; i < n; i++){
		maxs[i] = l - mins[i-1];
		mins[i] = 1 - maxs[i-1];
	}
	if(d > maxs[n-1] || d < mins[n-1]){
		puts("-1");
		return 0;
	}
	for(int i = n-1; i >= 1; i--){
		int k1 = l - d;
		int k2 = 1 - d;
		if(k1 >= mins[i-1] && k1 <= maxs[i-1]){
			ans[i] = l;
			d = k1;
		}
		else{
			ans[i] = 1;
			d = k2;
		}
		if(i == 1)
		 ans[i-1] = d;
	}
	printf("%d", ans[n-1]);
	for(int i = n-2; i >= 0; i--)
	 printf(" %d", ans[i]);
	puts("");
	
	return 0;
}


版权声明:本文为博主原创文章,未经博主允许不得转载。

Codeforces Round #406 (Div. 2):C. Berzerk(记忆化搜索解决博弈问题)

C. Berzerk time limit per test 4 seconds memory limit per test 256 megabytes input standard in...
  • Jaihk662
  • Jaihk662
  • 2017年03月24日 15:23
  • 783

【Codeforces Round 375 (Div 2) E】【欧拉回路Fleury算法 或网络流】One-Way Reform 每条边定向使得最多的点满足入度=出度

E. One-Way Reform time limit per test 2 seconds memory limit per test 256 megabytes ...
  • snowy_smile
  • snowy_smile
  • 2016年10月04日 10:20
  • 733

Codeforces Round #347 (Div. 2) B. Rebus(给你一个等式里面只含加减号凑出一个数)

B. Rebus time limit per test 1 second memory limit per test 256 megabytes input st...
  • acm_fighting
  • acm_fighting
  • 2016年04月25日 15:54
  • 315

Codeforces Round #362 (Div. 2)B. Barnicle(较坑模拟【菜鸡与大佬的区别】)

题目链接:http://codeforces.com/contest/697/problem/B【中文题意】给你一个浮点数的计数法表示形式,然后表示出他的正常形式,表示出的数不能有前导0也不能有后导0...
  • qq_32866009
  • qq_32866009
  • 2017年02月08日 15:44
  • 126

数学推公式——较难——Codeforces Round #187 (Div. 2)

题目链接: http://codeforces.com/contest/315/problem/C C. Sereja and Contest time limi...
  • CS_liuqing
  • CS_liuqing
  • 2013年06月16日 15:34
  • 1994

Codeforces Round #244 (Div. 2)(强连通分量,后缀数组)

A. Police Recruits #include #include #include #include using namespace std; int n; int main() { ...
  • u010660276
  • u010660276
  • 2014年05月23日 20:08
  • 419

Codeforces Round #248 (Div. 2) B题 【数据结构:树状数组】

题目链接:http://codeforces.com/contest/433/problem/B 题目大意:给n(1 ≤ n ≤ 105)个数据(1 ≤ vi ≤ 109),其中有m(1 ≤ m ≤...
  • u013912596
  • u013912596
  • 2014年05月24日 18:18
  • 706

Codeforces Round #312 (Div. 2) (第三题是位运算,好题)

比赛:点击打开链接 558A - Lala Land and Apple Trees 分析:从0坐标分开,负半轴一个数组,正半轴一个数组,来记录果树的左边和数量,可以用结构体数组来存储数据,其...
  • loveyou11111111
  • loveyou11111111
  • 2015年08月31日 16:30
  • 156

【打CF,学算法——三星级】CodeForces 689C Mike and Chocolate Thieves (二分)

题目链接:CF 689C 题面: C. Mike and Chocolate Thieves time limit per test 2 seconds memory limit ...
  • David_Jett
  • David_Jett
  • 2016年07月08日 10:55
  • 789

如何让Magic Mouse真正拥有Magic

Magic Mouse是苹果电脑的专属配件,它的庐山真面目就如题图一样,乍一看觉得除了外形像个鼠标,其它地方貌似都和普通的鼠标格格不入,起码连个最基本的滚轮都没有,但是既然敢叫Magic Mouse,...
  • littlewhite1989
  • littlewhite1989
  • 2014年12月03日 13:55
  • 2110
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Codeforces Round #143 (Div. 2)-B. Magic, Wizardry and Wonders
举报原因:
原因补充:

(最多只允许输入30个字)