HDU 5308 I Wanna Become A 24-Point Master (暴力枚举+构造)
2016-07-09 09:34
393 查看
题意:
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 10^9.
解析:1,2,3不可以,4 看样例。
首先对于任意一个数字i,都可以通过i*n/n来获得,需要占用i+1个。
对于数字0,至少需要两个,通过减和乘来实现。
因此,
24 = 24 + 0;
25 = 24*25/25;
26 = 26 - 2;
27 = 24*27/27 + 0;
........
然后剩下的暴力枚举就好。
5 = (5*5*5-5)/5;
6 = 6 + 6 + 6 + 6 + 0
7 = 7 + 7 + 7 + 3
...
9 = 9 + 9 + 9 - 3
......
这里不贴代码了,写的太丑不忍直视。
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 10^9.
解析:1,2,3不可以,4 看样例。
首先对于任意一个数字i,都可以通过i*n/n来获得,需要占用i+1个。
对于数字0,至少需要两个,通过减和乘来实现。
因此,
24 = 24 + 0;
25 = 24*25/25;
26 = 26 - 2;
27 = 24*27/27 + 0;
........
然后剩下的暴力枚举就好。
5 = (5*5*5-5)/5;
6 = 6 + 6 + 6 + 6 + 0
7 = 7 + 7 + 7 + 3
...
9 = 9 + 9 + 9 - 3
......
这里不贴代码了,写的太丑不忍直视。
相关文章推荐
- 数据库关系模式题型大全
- Asp.net中,点击GridView表头实现数据的排序
- DDL、DML和DCL的理解
- 欢迎使用CSDN-markdown编辑器
- 跟我一起学Multiple View Geometry多视图几何(6)
- php不定参数方法(函数)和可选参数方法(函数)
- 解决 MySQL 的 Table is marked as crashed and should be repaired 问题
- Linux基础-----find和重定向命令
- 面试冒泡排序
- SAP XI
- pta--七桥问题
- hdfs的shell命令
- 几个关于Service的知识点
- linux下使用eclipse编辑,链接,使用动态库的学习笔记
- IE浏览器10无法打开任何网页而其他浏览器可以的解决方法
- javax.servlet.ServletException: Filter execution threw an exception
- 贫血和富血
- NYOJ省赛来了
- C#处理猜拳问题的简单实例(非窗体)
- 经纬度距离计算