HDU 5308 I Wanna Become A 24-Point Master
来源:互联网 发布:华为it应用技术工程师 编辑:程序博客网 时间:2024/06/05 15:50
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5308
题面:
I Wanna Become A 24-Point Master
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 602 Accepted Submission(s): 249
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 withn numbers, which are all equal to n .
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
Input
There are no more then 100 testcases and there are no more then 5 testcases withn≥100 . Each testcase contains only one integer n (1≤n≤105)
Output
For each testcase:
If there is not any way to get 24 points, print a single line with -1.
Otherwise, letA be an array with 2n−1 numbers and at firsrt Ai=n (1≤i≤n) . You need to print n−1 lines and the i th 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 arrayA is used at most one tine.
3. The absolute value of the numerator and denominator of each element in arrayA is no more than 109
If there is not any way to get 24 points, print a single line with -1.
Otherwise, let
If your answer satisfies the following rule, we think your answer is right:
1.
2. Each position of the array
3. The absolute value of the numerator and denominator of each element in array
Sample Input
4
Sample Output
1 * 25 + 36 + 4
Source
2015 Multi-University Training Contest 2
解题:
如此之大的数据量,搜索是肯定不行。但还是被题目那句大于100的数据不会超过5组给蒙了一下。队友之前想着能不能从24往前搜,实则也是不行的。因为根本不知道前面究竟有什么数,又该对应怎样的操作。看了题解后,恍然大悟,就应该去构造。
枚举n比较小的情况,然后当n大于等于14时,可以去凑((4*n)/n)*((6*n)/n),虽然是12个n,但是仍要从14,开始,因为多余的n需要通过一次减法,多次乘法消去,最后再加上之前算出的24即可。
代码:
#include <iostream>#include <cstdio>#include <cmath>using namespace std;int main(){int n,tmp;while(~scanf("%d",&n)){//printf("%d:\n",n);if(n<=3)printf("-1\n");else if(n==4)printf("1 * 2\n5 + 3\n6 + 4\n");else if(n==5)printf("1 * 2\n3 / 6\n4 - 7\n5 * 8\n");else if(n==6)printf("1 + 2\n3 + 4\n5 - 6\n7 + 8\n10 - 9\n");else if(n==7)printf("1 + 2\n3 + 8\n9 / 4\n10 + 5\n11 + 6\n12 + 7\n");else if(n==8)printf("1 + 2\n3 + 9\n4 - 5\n11 * 6\n12 * 7\n13 * 8\n10 + 14\n");else if(n==9)printf("1 + 2\n3 + 10\n4 / 5\n6 / 7\n8 / 9\n11 - 12\n15 - 13\n 16 - 14\n");else if(n==10)printf("1 + 2\n3 / 4\n5 / 6\n7 / 8\n9 / 10\n11 + 12\n16 + 13\n17 + 14\n18 + 15\n");else if(n==11)printf("1 + 2\n3 / 4\n5 / 6\n7 - 8\n15 * 9\n16 * 10\n17 * 11\n12 + 13\n19 + 14\n20 + 18\n");else if(n==12)printf("1 + 2\n3 - 4\n5 * 14\n6 * 15\n7 * 16\n8 * 17\n9 * 18\n10 * 19\n11 * 20\n12 * 21\n13 + 22\n");else if(n==13) printf("1 + 2\n3 / 4\n5 / 6\n7 - 8\n17 * 9\n18 * 10\n19 * 11\n20 * 12\n21 * 13\n22 + 14\n23 - 15\n24 - 16\n");else{printf("1 + 2\n3 + 4\n5 + 6\n7 + 8\n9 + 10\n");printf("%d + %d\n%d + %d\n%d + %d\n",n+1,n+2,n+3,n+4,n+5,n+6);printf("%d / 11\n%d / 12\n",n+7,n+8);printf("%d * %d\n",n+9,n+10);printf("13 - 14\n");tmp=n-14;int i;for(i=0;i<tmp;i++){printf("%d * %d\n",n+12+i,15+i);}printf("%d + %d\n",n+11,n+12+tmp);}//printf("\n");}return 0;}
0 0
- HDU 5308 I Wanna Become A 24-Point Master
- hdu 5308 I Wanna Become A 24-Point Master
- HDU 5308 I Wanna Become A 24-Point Master
- HDOJ 5308 I Wanna Become A 24-Point Master 构造
- [多校2015.02.1009 构造] hdu 5308 I Wanna Become A 24-Point Master
- hdu 5308 I Wanna Become A 24-Point Master 2015 Multi-University Training Contest 2
- hdu 5308 I Wanna Become A 24-Point Master(2015 Multi-University Training Contest 2)
- HDU 5308 I Wanna Become A 24-Point Master(找规律+模拟)
- HDU 5308 I Wanna Become A 24-Point Master(2015多校第二场)
- hdu 5301 Buildings 5308 I Wanna Become A 24-Point Master(构造)
- HDU 5308 I Wanna Become A 24-Point Master(模拟+数论)
- hdu 5308 I Wanna Become A 24-Point Master(构造)
- hdu 5308 I Wanna Become A 24-Point Master(构造)
- HDU 5308 I Wanna Become A 24-Point Master (暴力枚举+构造)
- HDU 5308 I Wanna Become A 24-Point Master 循环(散乱的前缀+循环体)
- 找规律,模拟(HDU 5308,I Wanna Become A 24-Point Master)
- hdu5308 I Wanna Become A 24-Point Master 含 spj
- hdu5308 I Wanna Become A 24-Point Master(构造)
- Redis 配置文件说明
- 如何用textview设置drawableLeft属性
- storm基础框架分析
- Lowest Common Ancestor of a Binary Tree
- UVa 11538 Chess Queen 象棋中的皇后
- HDU 5308 I Wanna Become A 24-Point Master
- Android-对ListView的Adapter的一种简单封装
- Eclipse键盘控之路
- LigerUi中Grid表记录根据条件显示不同颜色和不同内容!(实例)
- uimsbf和 bslbf的含义
- Android Service,startService binderService 以及 AIDL
- 一个简单的多线程题目
- 揭秘百度核心技术:53位专家纯干货分享
- Android -- 数据库1