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
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.
n≥100.
Each testcase contains only one integer n (1≤n≤105)
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 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 109
4
1 * 2
5 + 3
6 + 4
解题:
如此之大的数据量,搜索是肯定不行。但还是被题目那句大于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;
}
HDU 5308 I Wanna Become A 24-Point Master的更多相关文章
- HDU 5308 I Wanna Become A 24-Point Master(2015多校第二场)
I Wanna Become A 24-Point Master Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 ...
- 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 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 ...
- hdu 5308 (2015多校第二场第9题)脑洞模拟题,无语
题目链接:http://acm.hdu.edu.cn/listproblem.php?vol=44 题意:给你n个n,如果能在n-1次运算之后(加减乘除)结果为24的输出n-1次运算的过程,如果不能输 ...
- HDU 5308 规律+模拟
给出N个数字N,要把全部数字用完.使用+-*/最后变为24.中间运算能够有有浮点数 对于1-14直接打表 15以上的能够通过13个同样数字得到24.然后使后面的数所有运算为0相加就可以 贴一发官方题解 ...
- HDU 5477 A Sweet Journey 水题
A Sweet Journey Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pi ...
- Kubeadm搭建高可用(k8s)Kubernetes v1.24.0集群
文章转载自:https://i4t.com/5451.html 背景 Kubernetes 1.24新特性 从kubelet中移除dockershim,自1.20版本被弃用之后,dockershim组 ...
- hdu1018--斯特灵公式
斯特灵公式 Wiki http://zh.wikipedia.org/wiki/斯特林公式 /** \brief hdu 1018 * * \param date 2014/7/24 * \param ...
- Puppet自动化部署-前期环境准备(2)
在安装Puppet环境之前需要配置好机器的基本配置,如规范网络地址IP.hostname,certname认证名称,ntp时间同步等配置完毕,完善的搭建自动化环境. 1.环境介绍 此处实现部署的环境是 ...
随机推荐
- [Swift]LeetCode1066. 校园自行车分配 II | Campus Bikes II
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...
- git的常用命令。。
git的常用命令.. git help <command> 显示command的help git show 显示某次提交的内容 git show $id git co -- <f ...
- xx网络--工具集合
-- D:\workspace\bajie_projram\BJ.srfcb\BJ.srfcb\BJ.srfcb 8jielicai_New\App_Code\common\pg.cs---GetHt ...
- BZOJ 4800 折半暴搜
思路: 把它拆成两半 分别搜一发 两部分分别排好序 用two-pointers扫一遍 就可以了. (读入也要用long long) //By SiriusRen #include <cstdi ...
- SnackDown Online Pre-elimination round A
1. 应该n是偶数,就行吧.应该判断1个人,只能出现一次吧. #include<bits/stdc++.h> #define pb push_back typedef long long ...
- C - Alice, Bob and Chocolate(贪心)
Problem description Alice and Bob like games. And now they are ready to start a new game. They have ...
- .net中实现aspnetpager分页
第一步首先导入aspnetpager控件,然后再把他从工具箱中拖出,代码如下: <webdiyer:AspNetPager ID="aspnetpager1" runat= ...
- SSIS SQL Server配置自动作业
目录: 一. 用SSMS配置作业,自助调度: 二.用SSMS调SSIS包: 一. 用SSMS配置作业,自助调度: 为验证数据,先创建一个表: CREATE TABLE test_table (id I ...
- [转载]MySql事物处理
事务处理在各种管理系统中都有着广泛的应用,比如人员管理系统,很多同步数据库操作大都需要用到事务处理.比如说,在人员管理系统中,你删除一个人员,你即需要删除人员的基本资料,也要删除和该人员相关的信息,如 ...
- OpenCV边缘检测的详细参数调节
1. findCountours 转载于http://blog.sina.com.cn/s/blog_7155fb1a0101a90h.html findContours函数,这个函数的原型为: &l ...