[模拟] hdu 5308 I Wanna Become A 24-Point Master

题意:

给你n个数,每个数都是n,

然后把这n个数加减乘除,每个数都必须用一次,且只能一次,并且运算完的数也都得用一次。

也就是做n-1次,问能不能得到24,输出过程 xi ? xj  第i个数与第j个数做?运算 这种形式

思路:

因为n有可能很大,那么肯定需要一种完美的构造

最简单的方法是构造出4*6

构造出4需要5个数,构造出6需要7个数

也就是最少需要12个数,剩下的数就是相减为0,然后乘就好了

但是需要注意的就是13是不满足这个规律的

所以1~13特判一下,14以上的按规律输出就好了~

代码:

#include"cstdlib"
#include"cstdio"
#include"cstring"
#include"cmath"
#include"queue"
#include"algorithm"
#include"iostream"
using namespace std;
int main()
{
    int n;
    while(scanf("%d",&n)!=-1)
    {
        if(n<=3)
        {
            puts("-1");
            continue;
        }
        if(n==4)
        {
            puts("1 * 2");
            puts("5 + 3");
            puts("6 + 4");
            continue;
        }
        if(n==5)
        {
            puts("1 * 2");
            puts("6 * 3");
            puts("7 - 4");
            puts("8 / 5");
            continue;
        }
        if(n==6)
        {
            puts("1 + 2");
            puts("3 + 4");
            puts("5 - 6");
            puts("7 + 8");
            puts("9 + 10");
            continue;
        }
        if(n==7)
        {
            puts("1 + 2");
            puts("8 + 3");
            puts("9 / 4");
            puts("5 / 6");
            puts("7 + 11");
            puts("12 * 10");
            continue;
        }
        if(n==8)
        {
            puts("1 + 2");
            puts("9 + 3");
            puts("5 - 4");
            puts("6 * 11");
            puts("7 * 12");
            puts("8 * 13");
            puts("10 + 14");
            continue;
        }
        if(n==9)
        {
            puts("1 / 2");  //10  1
            puts("3 - 10"); //11  8
            puts("4 + 5");  //12 18
            puts("12 + 6"); //13 27
            puts("13 / 7"); //14  3
            puts("11 * 14");//15 24
            puts("8 - 9");  //16  0
            puts("15 + 16");
            continue;
        }
        if(n==10)
        {
            puts("1 + 2");  //11 20
            puts("3 + 4");  //12 20
            puts("5 + 6");  //13 20
            puts("7 - 8");  //14 0
            puts("9 * 14"); //15 0
            puts("12 + 13");//16 40
            puts("16 / 10");//17 4
            puts("17 + 11");//18 24
            puts("18 + 15");
            continue;
        }
        if(n==11)
        {
            puts("1 + 2");  //12 22
            puts("3 + 4");  //13 22
            puts("13 / 5"); //14 2
            puts("14 + 12");//15 24
            puts("6 - 7");  //16 0
            puts("8 * 16"); //17 0
            puts("9 * 17"); //18 0
            puts("10 * 18");//19 0
            puts("11 * 19");//20 0
            puts("20 + 15");//21 24
            continue;
        }
        if(n==12)
        {
            puts("1 + 2"); //13 2n
            printf("%d + 3\n",n+1); //14 3n
            printf("%d + 4\n",n+2); //15 4n
            printf("%d + 5\n",n+3); //16 5n
            printf("%d + 6\n",n+4); //17 6n
            printf("%d / 7\n",n+5); //18(n+6) 6
            puts("8 + 9"); //19 2n
            printf("%d + 10\n",n+7); //20 3n
            printf("%d + 11\n",n+8); //21 4n
            printf("%d / 12\n",n+9); //22(n+10) 4
            printf("%d * %d\n",n+6,n+10); //23(n+11) 24
            continue;
        }
        if(n==13)
        {
            puts("1 / 2");  //14 1
            puts("3 - 14"); //15 12
            puts("4 + 5");  //16 26
            puts("16 / 6"); //17 2
            puts("15 * 17");//18 24
            puts("7 - 8");  //19 0
            puts("9 * 19"); //20 0
            puts("10 * 20"); //21 0
            puts("11 * 21"); //22 0
            puts("12 * 22"); //23 0
            puts("13 * 23"); //24 0
            puts("24 + 18"); //25 24
            continue;
        }
        puts("1 + 2"); //13 2n
        printf("%d + 3\n",n+1); //14 3n
        printf("%d + 4\n",n+2); //15 4n
        printf("%d + 5\n",n+3); //16 5n
        printf("%d + 6\n",n+4); //17 6n
        printf("%d / 7\n",n+5); //18(n+6) 6
        puts("8 + 9"); //19 2n
        printf("%d + 10\n",n+7); //20 3n
        printf("%d + 11\n",n+8); //21 4n
        printf("%d / 12\n",n+9); //22(n+10) 4
        printf("%d * %d\n",n+6,n+10); //23(n+11) 24
        puts("13 - 14");//n+12 0
        int tep=n+12;
        for(int i=15;i<=n;i++)
        {
            printf("%d * %d\n",i,tep);
            tep++;
        }
        printf("%d + %d\n",n+11,tep);
    }
    return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-08-04 17:29:05

[模拟] hdu 5308 I Wanna Become A 24-Point Master的相关文章

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): 366    Accepted Submission(s): 141 Special Judge Problem Description Recently Rikka falls in love with an old bu

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 K (Java/Others) Total Submission(s): 485    Accepted Submission(s): 191 Special Judge Problem Description Recently Rikka falls in love with an old bu

模拟 --- hdu 12878 : Fun With Fractions

Fun With Fractions Time Limit: 1000ms, Special Time Limit:2500ms, Memory Limit:65536KB Total submit users: 152, Accepted users: 32 Problem 12878 : No special judgement Problem description A rational number can be represented as the ratio of two integ

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

题目链接:http://acm.hdu.edu.cn/listproblem.php?vol=44 题意:给你n个n,如果能在n-1次运算之后(加减乘除)结果为24的输出n-1次运算的过程,如果不能输出-1. 思路:乍看起来,没什么规律,但是可以想象的是(n+n+n+n)/n=4,(n+n+n+n+n+n)/n=6,(n-n)*n*n*·····*n=0所以在n大于15的时候结果基本是固定的,只要对小于15的数一一输出就行(但是这题真是无语,算这种题目真是累,脑洞啊~~) 代码: 1 #incl

HDU 5308 规律+模拟

给出N个数字N,要把所有数字用完,使用+-*/最后变为24,中间运算可以有有浮点数 对于1-14直接打表 15以上的可以通过13个相同数字得到24,然后使后面的数全部运算为0相加即可 贴一发官方题解 #include "stdio.h" #include "string.h" int now; void pri(int l,int r) { int i; printf("%d - %d\n",l,l+1); now++; for (i=l+2;i

模拟/hdu 1008 Elevator

题意 开始电梯在0层 给出n个指令,每个代表下一步停到哪层 每往上一层需要6秒,往下一层需要4秒,停止需要5秒 求总时间 分析 数据很小,模拟即可喵- Accepted Code 1 /* 2 PROBLEM:hdu1007 3 AUTHER:Nicole Lam 4 MEMO:模拟 5 */ 6 7 8 #include<cstdio> 9 using namespace std; 10 11 int main() 12 { 13 int n; 14 scanf("%d"

HDOJ 5308 I Wanna Become A 24-Point Master 构造

构造题,前面十几个手工处理.... n很大时有很多构造方法,一阵乱搞就可以了...... I Wanna Become A 24-Point Master Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 128    Accepted Submission(s): 36 Special Judge Problem Description

[模拟] hdu 4452 Running Rabbits

题意: 两个人一个人在(1,1),一个人在(N,N) 给每个人每秒移动的速度v,和一个s代表移动s秒后左转方向 特别注意的是如果撞墙,要反弹回去,方向改变 比如在(1,1),往左走一步到(1,0) 其实就是走到了(1,2) 然后如果两个人见面那么交换方向并且不再左转! 思路: 直接模拟.. 代码: #include"cstdlib" #include"cstdio" #include"cstring" #include"cmath&qu

模拟生成一天温度数据,精确到秒

需求来源: 做一套养殖过程管理的系统,有养殖环境数据采集功能,硬件不到位,需要给相关LD演示,要求数据尽量真实.这就需要模拟生成一天的温度数据. 解决方案1: 指定范围随机数温度生成 结果就是这样了...太假... 解决方案2: 代码连续随机数生成: $wd_arr = array(); // 温度 //-------------温度-------------- // 生成连续的温度随机数 $wd_start = 21.6; $MAX_WD = 22.6; //最高温度22.6 $MIN_WD