I Wanna Become A 24-Point Master

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 897    Accepted Submission(s): 379
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 band 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
 
 

解题:打表+规律

可以发现当n等于12时,可以求解由
至于其余的数字,假设我们取n = 14 由于得到24,前面n个我们只用到了12个,那么我们可以将13 - 14,然后再加上 24 仍然是24

如果是15 ,我们可以13 - 14,然后差乘以 15 最后积加上24.。。以此类推

$\frac{n + n + n + n}{n} \times \frac{n + n + n + n + n + n}{n} = 24$
 
妈拉个巴子,latex公式不管用了
 
好吧 
 
(n+n+n+n)/n = 4;
(n+n+n+n+n+n)/n = 6;
4*6 = 24
 
所以当n大于12的时候,已经很明显可以解决了
 #include <bits/stdc++.h>
using namespace std;
const int maxn = ;
const char str[][maxn] = {
"-1",
"-1",
"-1",
"-1",
"1 * 2\n5 + 3\n6 + 4",
"1 * 2\n6 * 3\n7 - 4\n8 / 5",
"1 + 2\n7 + 3\n8 + 4\n9 + 5\n10 - 6",
"1 + 2\n8 + 3\n4 + 5\n10 + 6\n11 / 7\n9 + 12",
"1 + 2\n9 + 3\n4 + 5\n11 - 6\n12 - 7\n13 / 8\n10 + 14",
"1 + 2\n10 + 3\n4 + 5\n12 + 6\n13 / 7\n11 - 14\n15 - 8\n16 + 9",
"1 + 2\n3 + 4\n12 + 5\n13 + 6\n14 / 7\n11 + 15\n8 - 9\n17 / 10\n16 + 18",
"1 + 2\n3 + 4\n13 / 5\n12 + 14\n15 - 6\n16 + 7\n17 - 8\n18 + 9\n19 - 10\n20 + 11",
"1 + 2\n3 + 13\n4 + 14\n5 + 6\n7 + 16\n8 + 17\n9 + 15\n10 + 19\n18 / 11\n20 / 12\n21 * 22",
"1 + 2\n3 + 4\n15 / 5\n14 - 16\n17 - 6\n18 + 7\n19 - 8\n20 + 9\n21 - 10\n22 + 11\n23 - 12\n24 + 13",
"1 + 2\n3 + %d\n4 + %d\n5 + 6\n7 + %d\n8 + %d\n9 + %d\n10 + %d\n%d / 11\n%d / 12\n%d * %d\n"
};
int main() {
int n;
while(~scanf("%d",&n)) {
if(n <= ) puts(str[n]);
else {
printf(str[],n+,n+,n+,n+,n+,n+,n+,n+,n+,n+);
int last = n + ;
printf("%d - %d\n",,);
for(int i = ; i <= n; ++i)
printf("%d * %d\n",i,last++);
printf("%d + %d\n",n + ,last);
}
}
return ;
}

2015 Multi-University Training Contest 2 hdu 5308 I Wanna Become A 24-Point Master的更多相关文章

  1. 2015多校联合训练赛 hdu 5308 I Wanna Become A 24-Point Master 2015 Multi-University Training Contest 2 构造题

    I Wanna Become A 24-Point Master Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 ...

  2. 2015 Multi-University Training Contest 8 hdu 5390 tree

    tree Time Limit: 8000ms Memory Limit: 262144KB This problem will be judged on HDU. Original ID: 5390 ...

  3. 2015 Multi-University Training Contest 8 hdu 5383 Yu-Gi-Oh!

    Yu-Gi-Oh! Time Limit: 2000ms Memory Limit: 65536KB This problem will be judged on HDU. Original ID:  ...

  4. 2015 Multi-University Training Contest 8 hdu 5385 The path

    The path Time Limit: 2000ms Memory Limit: 65536KB This problem will be judged on HDU. Original ID: 5 ...

  5. 2015 Multi-University Training Contest 3 hdu 5324 Boring Class

    Boring Class Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Tota ...

  6. 2015 Multi-University Training Contest 3 hdu 5317 RGCDQ

    RGCDQ Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submi ...

  7. 2015 Multi-University Training Contest 10 hdu 5406 CRB and Apple

    CRB and Apple Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)To ...

  8. 2015 Multi-University Training Contest 10 hdu 5412 CRB and Queries

    CRB and Queries Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Other ...

  9. 2015 Multi-University Training Contest 6 hdu 5362 Just A String

    Just A String Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)T ...

随机推荐

  1. Codeforces 185A Plant( 递推关系 + 矩阵快速幂 )

    链接:传送门 题意:输出第 n 年向上小三角形的个数 % 10^9 + 7 思路: 设 Fn 为第 n 年向上小三角形的个数,经过分析可以得到 Fn = 3 * Fn-1 + ( 4^(n-1) - ...

  2. 模板 FFT 快速傅里叶变换

    FFT模板,原理不难,优质讲解很多,但证明很难看太不懂 这模板题在bzoj竟然是土豪题,服了 #include <cmath> #include <cstdio> #inclu ...

  3. Python中的itertools.product

    例子1:import itertoolsa = itertools.product([1,2,3],[100,200])print(a)for item in itertools.product([1 ...

  4. 重启rsyslog服务时出现问题(误删/var/log/messages解决方案)

    今天修改了/etc/rsyslog.conf中的内容后,想着要通过systemctl restart rsyslog重启服务,但是执行完命令后,总感觉/etc/rsyslog.conf中修改的内容没有 ...

  5. cocos2d-x-3.3rc2-003 cocos中的引用计数和自己主动释放池

    点击打开链接

  6. POJ-3264-Balanced Lineup-单点更新

    题目链接:id=3264">http://poj.org/problem? id=3264 这是一个单点更新的模板题,就不详解了,HDU敌兵布阵那题我有详解:链接:http://blo ...

  7. 爬虫框架webmagic与spring boot的结合使用--转

    原文地址:http://www.jianshu.com/p/c3fc3129407d 1. 爬虫框架webmagic WebMagic是一个简单灵活的爬虫框架.基于WebMagic,你可以快速开发出一 ...

  8. winforms控件

     我们在开发窗体应用时,控件是必不可少的今天我们就来认识一下控件 在认识控件之前还要先来认识一下窗体具体如下: 认识窗体和控件 窗体                                   ...

  9. KMP算法中求next数组的实质

    在串匹配模式中,KMP算法较蛮力法是高效的算法,我觉得其中最重要的一点就是求next数组: 看了很多资料才弄明白求next数组是怎么求的,我发现我的忘性真的比记性大很多,每次看到KMP算法求next数 ...

  10. (转载)Android:学习AIDL,这一篇文章就够了(下)

    前言 上一篇博文介绍了关于AIDL是什么,为什么我们需要AIDL,AIDL的语法以及如何使用AIDL等方面的知识,这一篇博文将顺着上一篇的思路往下走,接着介绍关于AIDL的一些更加深入的知识.强烈建议 ...