HDU 5308 I Wanna Become A 24-Point Master
生活随笔
收集整理的這篇文章主要介紹了
HDU 5308 I Wanna Become A 24-Point Master
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
題目鏈接: 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 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 n≥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, 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 109
Sample Input 4
Sample Output 1 * 2 5 + 3 6 + 4
Source 2015 Multi-University Training Contest 2
解題:
??? 如此之大的數(shù)據(jù)量,搜索是肯定不行。但還是被題目那句大于100的數(shù)據(jù)不會超過5組給蒙了一下。隊友之前想著能不能從24往前搜,實則也是不行的。
由于根本不知道前面到底有什么數(shù)。又該相應(yīng)如何的操作??戳祟}解后,恍然大悟。就應(yīng)該去構(gòu)造。
??? 枚舉n比較小的情況,然后當n大于等于14時,能夠去湊((4*n)/n)*((6*n)/n),盡管是12個n,可是仍要從14,開始,由于多余的n須要通過一次減法,多次乘法消去。最后再加上之前算出的24就可以。
代碼:
轉(zhuǎn)載于:https://www.cnblogs.com/llguanli/p/6970459.html
總結(jié)
以上是生活随笔為你收集整理的HDU 5308 I Wanna Become A 24-Point Master的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: yum安装时出现:Cannot retr
- 下一篇: Yii学习笔记之二(使用gii生成一个简