首页 > 其他 > 详细

HDU 5308 I Wanna Become A 24-Point Master(2015多校第二场)

时间:2015-07-24 17:25:41      阅读:239      评论:0      收藏:0      [点我收藏+]
 
Problem Description
 
Recently Rikka falls in love with an old but interesting game -- 24 points. She wants to become a master of this game, so she asks Yuta to give her some   problems to practice.

Quickly, Rikka solved almost all of the problems but the remained one is really difficult:

In this problem, you need to write a program which can get 24 points with n numbers, which are all equal to n.
 
Input
 
There are no more then 100 testcases and there are no more then 5 testcases with n100. Each testcase contains only one integer n (1n105)
 
Output
 
For each testcase:

If there is not any way to get 24 points, print a single line with -1.

Otherwise, let A be an array with 2n1 numbers and at firsrt Ai=n (1in). You need to print n1 lines and the ith line contains one integer a, one char b and then one integer c, where 1a,c<n+i and b is "+","-","*" or "/". This line means that you let Aa and Ac do the operation b and store the answer into An+i.

If your answer satisfies the following rule, we think your answer is right:

1. A2n1=24

2. Each position of the array A is used at most one tine.

3. The absolute value of the numerator and denominator of each element in array A is no more than 109
 
Sample Input
 
4
 
Sample Output
 
1 * 2
5 + 3
6 + 4
 
题意:有一个长度为2n-1的数组,数组中前n个数字都为n,对数组进行n-1次+-*/操作,将第i次的操作结果存入An+i中,使得A2n-1等于24,数组中每个数只能使用一次,中间运算可以有有浮点数。
 
题解:对于1-13直接打表,14以上数可以通过前12个相同数字得到24(转换成4*6),对于多余的n,我们可以用2个相减得0把多余的n乘掉。

HDU 5308 I Wanna Become A 24-Point Master(2015多校第二场)

原文:http://www.cnblogs.com/hgfblog/p/4673758.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!