题目链接: 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

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 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
 
Sample Input
4
 
Sample Output
1 * 2
5 + 3
6 + 4
 
Source
 



解题:

    如此之大的数据量,搜索是肯定不行。但还是被题目那句大于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的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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 ...

  4. hdu 5308 (2015多校第二场第9题)脑洞模拟题,无语

    题目链接:http://acm.hdu.edu.cn/listproblem.php?vol=44 题意:给你n个n,如果能在n-1次运算之后(加减乘除)结果为24的输出n-1次运算的过程,如果不能输 ...

  5. HDU 5308 规律+模拟

    给出N个数字N,要把全部数字用完.使用+-*/最后变为24.中间运算能够有有浮点数 对于1-14直接打表 15以上的能够通过13个同样数字得到24.然后使后面的数所有运算为0相加就可以 贴一发官方题解 ...

  6. HDU 5477 A Sweet Journey 水题

    A Sweet Journey Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pi ...

  7. Kubeadm搭建高可用(k8s)Kubernetes v1.24.0集群

    文章转载自:https://i4t.com/5451.html 背景 Kubernetes 1.24新特性 从kubelet中移除dockershim,自1.20版本被弃用之后,dockershim组 ...

  8. hdu1018--斯特灵公式

    斯特灵公式 Wiki http://zh.wikipedia.org/wiki/斯特林公式 /** \brief hdu 1018 * * \param date 2014/7/24 * \param ...

  9. Puppet自动化部署-前期环境准备(2)

    在安装Puppet环境之前需要配置好机器的基本配置,如规范网络地址IP.hostname,certname认证名称,ntp时间同步等配置完毕,完善的搭建自动化环境. 1.环境介绍 此处实现部署的环境是 ...

随机推荐

  1. HTML <!DOCTYPE>标签

    一般一个基本html页面的结构,如下代码所示: <html> <head> <title>我是基本的页面结构</title> </head> ...

  2. IO流遍历文件夹下所有文件问题

    import java.io.File; /** * @author 王恒 * @datetime 2017年4月20日 下午2:24:32 * @description 递归调用 * */ publ ...

  3. 关于如何将_variant_t型转化为int型和string类型

    1)将_variant_t型转化为int型 关于将_variant_t型转化为int型,网上有好多好多参考,但好多都很复杂并且还不对,其实整个转化过程就只一行代码可以搞定: _variant_t a; ...

  4. springBoot jar/war打包部署问题

    先给pom.xml配置导出插件 <!--配置插件将Maven 插件 导出成为jar --> <plugin> <groupId>org.springframewor ...

  5. Android贝塞尔曲线应用-跳动的水滴

    主要通过6个控制点实现. val startPoint = PointF() val endPoint = PointF() val control1 = PointF() val control2 ...

  6. mysql自动添加时间的方法

    时间添加方法,可以在编辑数据时方便时间选择输入: 将时间列DataType设为timestamp,设定其默认值为CURRENT_TIMESTAMP. 这样每次插入一条新纪录,数据库会自动在时间段存储当 ...

  7. oracle从入门到精通复习笔记续集之PL/SQL(轻量版)

    复习内容: PL/SQL的基本语法.记录类型.流程控制.游标的使用. 异常处理机制.存储函数/存储过程.触发器. 为方便大家跟着我的笔记练习,为此提供数据库表文件给大家下载:点我下载 为了要有输出的结 ...

  8. selenium有多个窗口时操作某个窗口的内容

    这个页面点击html/css后会弹出一个新的窗口,此时要操作新的窗口的内容,使用switchTo 跳转代码 driver.get("https://www.imooc.com"); ...

  9. 【汇编】MASM6.15几个简单的汇编程序

    /***************通过调用(INT 21H)表中的01h号功能号从键盘输入一个字符并回显到视频显示器上*****************/ DATAS SEGMENT ;此处输入数据段代 ...

  10. mysql中int、bigint、smallint 和 tinyint的区别与长度

    各种整形,总结留作参考. bigint 从 -2^63 (-9223372036854775808) 到 2^63-1 (9223372036854775807) 的整型数据(所有数字).存储大小为 ...