您的位置:首页 > 其它

HDU 5308 I Wanna Become A 24-Point Master (暴力枚举+构造)

2016-07-09 09:34 393 查看
题意:

let A be an array with 2n−1 numbers and at firsrt Ai=n (1≤i≤n). You need to print n−1 lines and the ith line contains one integer a, one char b and then one integer c, where 1≤a,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. A2n−1=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 10^9.

解析:1,2,3不可以,4 看样例。

首先对于任意一个数字i,都可以通过i*n/n来获得,需要占用i+1个。

对于数字0,至少需要两个,通过减和乘来实现。

因此,

24 = 24 + 0;

25 = 24*25/25;

26 = 26 - 2;

27 = 24*27/27 + 0;

........

然后剩下的暴力枚举就好。

5 = (5*5*5-5)/5;

6 = 6 + 6 + 6 + 6 + 0

7 = 7 + 7 + 7 + 3

...

9 = 9 + 9 + 9 - 3

......

这里不贴代码了,写的太丑不忍直视。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: