2015 Multi-University Training Contest 2 hdu 5308 I Wanna Become A 24-Point Master I Wanna Become A 24-Point Master

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 897    Accepted Submission(s): 379
Special Judge


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.
 
Input
There are no more then 100 testcases and there are no more then 5 testcases with )
 
Output
For each testcase:

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

Otherwise, let 9
 
Sample Input
4
 
Sample Output
1 * 2
5 + 3
6 + 4
 
Source
 
 

解题:打表+规律

可以发现当n等于12时,可以求解由
至于其余的数字,假设我们取n = 14 由于得到24,前面n个我们只用到了12个,那么我们可以将13 - 14,然后再加上 24 仍然是24

如果是15 ,我们可以13 - 14,然后差乘以 15 最后积加上24.。。以此类推

$frac{n + n + n + n}{n} imes frac{n + n + n + n + n + n}{n} = 24$
 
妈拉个巴子,latex公式不管用了
 
好吧 
 
(n+n+n+n)/n = 4;
(n+n+n+n+n+n)/n = 6;
4*6 = 24
 
所以当n大于12的时候,已经很明显可以解决了
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 const int maxn = 2100;
 4 const char str[16][maxn] = {
 5     "-1",
 6     "-1",
 7     "-1",
 8     "-1",
 9     "1 * 2
5 + 3
6 + 4",
10     "1 * 2
6 * 3
7 - 4
8 / 5",
11     "1 + 2
7 + 3
8 + 4
9 + 5
10 - 6",
12     "1 + 2
8 + 3
4 + 5
10 + 6
11 / 7
9 + 12",
13     "1 + 2
9 + 3
4 + 5
11 - 6
12 - 7
13 / 8
10 + 14",
14     "1 + 2
10 + 3
4 + 5
12 + 6
13 / 7
11 - 14
15 - 8
16 + 9",
15     "1 + 2
3 + 4
12 + 5
13 + 6
14 / 7
11 + 15
8 - 9
17 / 10
16 + 18",
16     "1 + 2
3 + 4
13 / 5
12 + 14
15 - 6
16 + 7
17 - 8
18 + 9
19 - 10
20 + 11",
17     "1 + 2
3 + 13
4 + 14
5 + 6
7 + 16
8 + 17
9 + 15
10 + 19
18 / 11
20 / 12
21 * 22",
18     "1 + 2
3 + 4
15 / 5
14 - 16
17 - 6
18 + 7
19 - 8
20 + 9
21 - 10
22 + 11
23 - 12
24 + 13",
19     "1 + 2
3 + %d
4 + %d
5 + 6
7 + %d
8 + %d
9 + %d
10 + %d
%d / 11
%d / 12
%d * %d
"
20 };
21 int main() {
22     int n;
23     while(~scanf("%d",&n)) {
24         if(n <= 13) puts(str[n]);
25         else {
26             printf(str[14],n+1,n+2,n+4,n+5,n+3,n+7,n+6,n+8,n+9,n+10);
27             int last = n + 12;
28             printf("%d - %d
",13,14);
29             for(int i = 15; i <= n; ++i)
30                 printf("%d * %d
",i,last++);
31             printf("%d + %d
",n + 11,last);
32         }
33     }
34     return 0;
35 }
View Code