HDU 5308 I Wanna Become A 24-Point Master(2015多校第二场)
2015-07-24 10:18
375 查看
I Wanna Become A 24-Point Master
Time Limit: 2000/1000 MS (Java/Others) MemoryLimit: 65536/65536 K (Java/Others)
Total Submission(s): 485 Accepted Submission(s): 191
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
numbers,
which are all equal to
.
Input
There are no more then 100 testcases and there are no more then 5 testcases with
.
Each testcase contains only one integer
Output
For each testcase:
If there is not any way to get 24 points, print a single line with -1.
Otherwise, let
be
an array with
numbers
and at firsrt
.
You need to print
lines
and the
th
line contains one integer
,
one char
and
then one integer c, where
and
is
"+","-","*" or "/". This line means that you let
and
do
the operation
and
store the answer into
.
If your answer satisfies the following rule, we think your answer is right:
1.
2. Each position of the array
is
used at most one tine.
3. The absolute value of the numerator and denominator of each element in array
is
no more than
Sample Input
4
Sample Output
1 * 2
5 + 3
6 + 4
Source
2015 Multi-University Training Contest 2
#include <iostream> #include <cstring> #include <cstdlib> #include <cstdio> #include <algorithm> using namespace std; int N; int main() { while(scanf("%d", &N)!=EOF) { if(N == 1 || N == 2 || N == 3 ) printf("-1\n"); else if(N == 4) { printf("1 * 2\n"); printf("5 + 3\n"); printf("6 + 4\n"); } else if(N == 5) { printf("1 * 2\n");//6 25 printf("3 * 6\n");//7 125 printf("7 - 4\n");//8 120 printf("8 / 5\n");//9 24 } else if(N == 6) { printf("1 * 2\n");//7 36 printf("7 - 3\n");//8 30 printf("8 - 4\n");//9 24 printf("9 + 5\n");//10 30 printf("10 - 6\n");//11 24 } else if(N == 7) { printf("1 / 2\n");//8 1 printf("3 + 8\n");//9 8 printf("4 + 5\n");//10 14 printf("10 + 6\n");//11 21 printf("11 / 7\n");//12 3 printf("12 * 9\n");//13 24 } else if(N == 8) { printf("1 + 2\n");//9 16 printf("3 + 9\n");//10 24 printf("4 - 5\n");//11 0 printf("11 * 6\n");//12 0 printf("12 * 7\n");//13 0 printf("13 * 8\n");//14 0 printf("14 + 10\n");//15 24 } else if(N == 9) { printf("1 + 2\n");//10 18 printf("10 + 3\n");//11 27 printf("11 * 4\n");//12 243 printf("12 / 5\n");//13 27 printf("6 + 7\n");//14 18 printf("14 + 8\n");//15 27 printf("15 / 9\n");//16 3 printf("13 - 16\n");//17 24 } else if(N == 10) { printf("1 + 2\n");//11 20 printf("3 + 4\n");//12 20 printf("12 + 5\n");//13 30 printf("13 + 6\n");//14 40 printf("14 / 7\n");//15 4 printf("11 + 15\n");//16 24 printf("8 - 9\n");//17 0 printf("17 / 10\n");//18 0 printf("16 + 18\n");//19 24 } else if(N == 11) { printf("1 + 2\n");//12 22 printf("12 / 3\n");//13 2 printf("13 + 4\n");//14 13 printf("14 + 5\n");//15 24 printf("15 + 6\n");//16 35 printf("16 + 7\n");//17 46 printf("17 + 8\n");//18 57 printf("18 - 9\n");//19 46 printf("19 - 10\n");//20 35 printf("20 - 11\n");//21 24 } else if(N >= 12 && N % 2 == 0) { printf("1 + 2\n");//N+1 2*N printf("%d + 3\n",N+1);//N+2 3*N printf("4 + 5\n");//N+3 2*N printf("%d + 6\n",N+3);//N+4 3*N printf("%d + 7\n",N+4);//N+5 4*N printf("8 + 9\n");//N+6 2*N printf("%d / 10\n",N+2);//N+7 3 printf("%d / 11\n",N+5);//N+8 4 printf("%d / 12\n",N+6);//N+9 2 printf("%d * %d\n",N+7,N+8);//N+10 12 printf("%d * %d\n",N+9,N+10);//N+11 24 for(int i=0;i<(N-12)/2;i++) { printf("%d + %d\n",N+11+2*i,13+i*2);//N+12+2*i printf("%d - %d\n",N+12+2*i,14+i*2);//N+13+2*i } } else if(N>=13 && N % 2 == 1) { printf("1 + 2\n");//N+1 2*N printf("%d + 3\n",N+1);//N+2 3*N printf("4 + 5\n");//N+3 2*N printf("%d + 6\n",N+3);//N+4 3*N printf("%d + 7\n",N+4);//N+5 4*N printf("%d + 8\n",N+5);//N+6 5*N printf("%d + 9\n",N+6);//N+7 6*N printf("%d + 10\n",N+7);//N+8 7*N printf("%d + 11\n",N+8);//N+9 8*N printf("%d / 12\n",N+2);//N+10 3 printf("%d / 13\n",N+9);//N+11 8 printf("%d * %d\n",N+10,N+11);//N+12 24 for(int i=0;i<(N-13)/2;i++) { printf("%d + %d\n",N+12+2*i,14+i*2);//N+13+2*i printf("%d - %d\n",N+13+2*i,15+i*2);//N+14+2*i } } } }
相关文章推荐
- 五种基于RGB色彩空间统计的皮肤检测算法
- 五种基于RGB色彩空间统计的皮肤检测算法
- 实习16天
- 五种基于RGB色彩空间统计的皮肤检测算法
- HDU 1710 二叉树遍历
- Spring+iBatis+Atomikos实现JTA事务
- iOS appdelegate 中将自定义的视图作为启动视图
- 五种基于RGB色彩空间统计的皮肤检测算法 分类: 视频图像处理 2015-07-24 10:18 48人阅读 评论(0) 收藏
- java中全排列的生成算法汇总
- 图像处理------图像梯度效果
- 图像处理------图像梯度效果
- 超详细介绍 图像处理(卷积)
- 论文参考文献
- 图像处理------图像梯度效果
- html中<li></li>中使用<br>和<li></li>外面使用<br>
- 有没有一个命令把linux下的分区的各个卷标都对应着显示出来?
- js中运算符的优先级
- Fragment 设置主题
- 图像处理------图像梯度效果 分类: 视频图像处理 2015-07-24 10:17 48人阅读 评论(0) 收藏
- 用GDB调试程序