日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

HDU 5308 I Wanna Become A 24-Point Master

發布時間:2023/12/20 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 HDU 5308 I Wanna Become A 24-Point Master 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題目鏈接: 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 n100. Each testcase contains only one integer n?(1n105)
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?(1in). You need to print n?1 lines and the ith line contains one integer a, one char b and then one integer c, where 1a,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

解題:
??? 如此之大的數據量,搜索是肯定不行。但還是被題目那句大于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; }




轉載于:https://www.cnblogs.com/llguanli/p/6970459.html

總結

以上是生活随笔為你收集整理的HDU 5308 I Wanna Become A 24-Point Master的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。