HDOJ 5308 I Wanna Become A 24

构造题,前面十几个手工处理….

n很大时有很多构造方法,一阵乱搞就可以了……

I Wanna Become A 24-Point MasterTime Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 128Accepted Submission(s): 36Special 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 withnumbers, 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, letbe an array withnumbers and at firsrt. You need to printlines and theth line contains one integer, one charand then one integer c, whereis "+","-","*" or "/". This line means that you letdo the operationand store the answer into.If your answer satisfies the following rule, we think your answer is right:1.2. Each position of the arrayis used at most one tine.3. The absolute value of the numerator and denominator of each element in arrayis no more than

Sample Input

4

Sample Output

1 * 25 + 36 + 4

Source

#include <iostream>#include <cstring>#include <cstdio>#include <algorithm>#include <set>#include <queue>#include <stack>#include <cmath>#include <cstdlib>using namespace std;int dy[55];void db(int x ){if ( x==1)printf("-1\n");if ( x==2)printf("-1\n");if ( x==3)printf("-1\n");if ( x==4){puts("1 * 2");puts("5 + 3");puts("6 + 4");}if ( x==5){puts("1 / 2");puts("6 / 3");puts("4 – 7");puts("5 * 8");}if ( x==6){puts("1 + 2");puts("7 + 3");puts("8 + 4");puts("9 * 5");puts("10 / 6");}if ( x==7){puts("1 * 2"); // 8puts("3 / 4"); // 9puts("8 – 9"); // 10puts("5 + 6"); // 11puts("11 / 7"); // 12puts("10 / 12"); // 13}if ( x==8){puts("1 + 2"); // 9puts("3 + 9"); // 10puts("4 – 5"); // 11puts("11 * 6"); // 12puts("12 * 7"); // 13puts("13 * 8"); // 14puts("10 + 14"); // 15}if ( x==9 ){puts("1 + 2"); // 10puts("10 + 3");puts("11 + 4");puts("12 + 5");puts("13 + 6"); // 14puts("14 / 7"); // 15puts("15 + 8");puts("16 + 9");}if ( x== 10){puts("1 / 2"); //11puts("3 / 4"); //12puts("5 / 6"); // 13puts("7 / 8"); // 14puts("9 + 10"); //15puts("15 + 11");puts("16 + 12");puts("17 + 13");puts("18 + 14");}if ( x== 11){puts("1 + 2"); //12puts("12 / 3"); // 13puts("13 * 4"); // 14puts("14 / 5"); //15puts("15 * 6"); //16puts("16 / 7"); //17puts("17 * 8"); // 18puts("18 / 9"); //19puts("19 + 10"); //20puts("20 + 11"); // 21}if ( x== 12){puts("1 + 2"); // 13puts("13 + 3"); // 14puts("14 – 4");puts("15 + 5");puts("16 – 6");puts("17 + 7");puts("18 – 8");puts("19 + 9");puts("20 – 10");puts("21 + 11");puts("22 – 12");}if (x == 24){puts("1 – 2");puts("25 * 3");puts("26 * 4");puts("27 * 5");puts("28 * 6");puts("29 * 7");puts("30 * 8");puts("31 * 9");puts("32 * 10");puts("33 * 11");puts("34 * 12");puts("35 * 13");puts("36 * 14");puts("37 * 15");puts("38 * 16");puts("39 * 17");puts("40 * 18");puts("41 * 19");puts("42 * 20");puts("43 * 21");puts("44 * 22");puts("45 * 23");puts("46 + 24");}if (x == 26){puts("1 / 2"); // 27puts("3 / 4"); // 28puts("27 + 28"); // 29puts("5 – 29"); // 30puts("30 * 6");puts("31 / 7");puts("32 * 8");puts("33 / 9");puts("34 * 10");puts("35 / 11");puts("36 * 12");puts("37 / 13");puts("38 * 14");puts("39 / 15");puts("40 * 16");puts("41 / 17");puts("42 * 18");puts("43 / 19");puts("44 * 20");puts("45 / 21");puts("46 * 22");puts("47 / 23");puts("24 – 25");puts("49 * 26");puts("48 + 50");}}void solve25(){int n = 25;int t = 1, e = dy[n + 1];printf("%d + %d\n", dy[t], dy[t + 1]);t += 2;for(int i = 0; i < 22; i++){printf("%d + %d\n", dy[t++], e++);}printf("%d / %d\n", e++, dy[t++]);}void xiao(int n, int c){int t = 1, e = n + 1;printf("%d – %d\n", t, t + 1);t += 2;for(int i = 2; i < c; i++){printf("%d * %d\n", t++, e++);}printf("%d + %d\n", e++, t++);int i;//printf("n – c = %d\n", n – c);for(i = 1; i < n – c; i++){dy[i] = t++;}for(; i <= 55; i++){dy[i] = e++;}//printf("*****%d\n", dy[26]);//for(int i = 1; i <= 26; i++) printf("%d ", dy[i]);printf("\n");}void solve24(int n){if(n == 26){return;}for(int i = 1; i <= 88; i++) dy[i] = i;if(n >= 27){xiao(n, n – 25);}solve25();}void solve13(int n){for(int i = 1; i < 55; i++) dy[i] = i;if(n > 13){xiao(n, 2 * n – 26);}int m = 26 – n;int t = 1, e = dy[m + 1];if(m > 3){printf("%d + %d\n", dy[t], dy[t + 1]);t += 2;}else{e–;}for(int i = 0; i < m – 4; i++){printf("%d + %d\n", dy[t++], e++);}printf("%d / %d\n", e++, dy[t++]);printf("%d + %d\n", dy[t++], e++);}void solve(int n){if(n>=1&&n<=12) db(n);else if(n==24||n==26) db(n);else if(n > 24){solve24(n);}else if(n >= 13){solve13(n);}}int main(){int n;while(scanf("%d", &n) != EOF){solve(n);}return 0;}

版权声明:本文为博主原创文章,,未经博主允许不得转载。

从此便踏上征途,也许会孤独一程。

HDOJ 5308 I Wanna Become A 24

相关文章:

  • 【算法】直接插入排序C语言实现
  • 嵌入式 FAAC1.28 在海思HI3518C/HI3518A平台linux中的编译优化
  • Android 动画animation 深入分析
  • 你感兴趣的文章:

    标签云:

    亚洲高清电影在线, 免费高清电影, 八戒影院夜间, 八戒电影最新大片, 出轨在线电影, 午夜电影院, 在线影院a1166, 在线电影院, 在线观看美剧下载, 日本爱情电影, 日韩高清电影在线, 电影天堂网, 直播盒子app, 聚合直播, 高清美剧, 高清美剧在线观看 EhViewer-E站, E站, E站绿色版, qqmulu.com, qq目录网, qq网站目录,