2015 Multi-University Training Contest 2 hdu 5308 I Wanna Become A 24-Point Master
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
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.
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
解题:打表+规律
可以发现当n等于12时,可以求解由
至于其余的数字,假设我们取n = 14 由于得到24,前面n个我们只用到了12个,那么我们可以将13 - 14,然后再加上 24 仍然是24
如果是15 ,我们可以13 - 14,然后差乘以 15 最后积加上24.。。以此类推
#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的更多相关文章
- 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 ...
- 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 ...
- 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: ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- [中文] 以太坊(Ethereum )白皮书
以太坊(Ethereum ):下一代智能合约和去中心化应用平台 翻译|巨蟹 .少平 译者注|中文读者可以到以太坊爱好者社区(www.ethfans.org)获取最新的以太坊信息. 当中本聪在2009年 ...
- 小学生都能学会的python(编码 and 字符串)
小学生都能学会的python(编码 and 字符串) 一,编码 最早的计算机编码是ASCII. 有英文+数字+特殊字符 8bit => 1byte 没有中文, 后面的编码必须兼容ASCII ...
- JS深拷贝拷贝的区别?
拷贝拷贝引用,共享内存 深拷贝拷贝实例,不共享内存 1. 浅拷贝:当一个对象拷贝另一个对象的数据时,只要一个对象的数据发生改变时,另一个对象的数据也会发生改变,因为浅拷贝拷贝的是引用的地址 实现方 ...
- java结合jQuery.ajax实现左右菜单联动刷新列表内容
http://域名/一级菜单ID-二级菜单ID/ 用这种URL请求页面,出现如图所看到的内容: 该页面包括四部分,顶部文件夹+左側菜单+右側菜单+右下側数据列表. 左側菜单包括一级菜单和二级菜单,点击 ...
- hdu1525 Euclid's Game , 基础博弈
http://acm.hdu.edu.cn/showproblem.php?pid=1525 题意: 两人博弈,给出两个数a和b, 较大数减去较小数的随意倍数.结果不能小于0,将两个数随意一个数减到0 ...
- Git-删除本地文件夹的repository(本地仓库)
安装git软件后.有些文件夹里会出现带有?的图标,右键菜单上会有"Git-Sync"或者"Git-Commit"等命令:正常的应该是"Git-Clon ...
- Git 跟 GitHub 是什么关系?
Git 跟 GitHub 是什么关系? 大概就是「魔兽争霸」与「对战平台」的关系吧. git是一个版本控制工具github是一个用git做版本控制的项目托管平台. git是一个版本管理工具,githu ...
- Kettle和ETL的基本构成
不多说,直接上干货! 这里,我说的通俗易懂点,好方便大家的理解. ETL解决方案就像业务流程一样,具有输入.输出,以及一个或多个工作环节,处理步骤.同样的,这些步骤也具有输入和输出,并可以执行将一个输 ...
- 洛谷P1067 多项式输出(模拟)
题目描述 一元 n 次多项式可用如下的表达式表示: 其中,aixi称为 i 次项,ai 称为 i 次项的系数.给出一个一元多项式各项的次数和系数,请按照如下规定的格式要求输出该多项式: 1. 多项式中 ...
- 你不知道的JavaScript(四)数值
JS中只有一种数值类型,即number.不管是整数还是小数都属于number类型,事实上JS并不区分小数和整数. <div> <script type="text/java ...