zoukankan      html  css  js  c++  java
  • 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 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  numbers, which are all equal to .
     

    Input
    There are no more then 100 testcases and there are no more then 5 testcases with . Each testcase contains only one integer 
     

    Output
    For each testcase:

    If there is not any way to get 24 points, print a single line with -1.

    Otherwise, let  be an array with  numbers and at firsrt . You need to print  lines and the th line contains one integer , one char  and then one integer c, where  and  is "+","-","*" or "/". This line means that you let  and  do the operation  and store the answer into .

    If your answer satisfies the following rule, we think your answer is right:

    1. 

    2. Each position of the array  is used at most one tine.

    3. The absolute value of the numerator and denominator of each element in array  is no more than 
     

    Sample Input
    4
     

    Sample Output
    1 * 2 5 + 3 6 + 4
     

    Source
    #include <iostream>
    #include <cstring>
    #include <cstdlib>
    #include <cstdio>
    #include <algorithm>
    using namespace std;
    int N;
    int main()
    {
        while(scanf("%d", &N)!=EOF)
        {
            if(N == 1 || N == 2 || N == 3 ) printf("-1
    ");
            else if(N == 4)
            {
                printf("1 * 2
    ");
                printf("5 + 3
    ");
                printf("6 + 4
    ");
            }
            else if(N == 5)
            {
                printf("1 * 2
    ");//6  25
                printf("3 * 6
    ");//7  125
                printf("7 - 4
    ");//8  120
                printf("8 / 5
    ");//9  24
            }
            else if(N == 6)
            {
                printf("1 * 2
    ");//7  36
                printf("7 - 3
    ");//8  30
                printf("8 - 4
    ");//9  24
                printf("9 + 5
    ");//10 30
                printf("10 - 6
    ");//11 24
            }
            else if(N == 7)
            {
                printf("1 / 2
    ");//8  1
                printf("3 + 8
    ");//9 8
                printf("4 + 5
    ");//10 14
                printf("10 + 6
    ");//11 21
                printf("11 / 7
    ");//12 3
                printf("12 * 9
    ");//13 24
            }
            else if(N == 8)
            {
                printf("1 + 2
    ");//9  16
                printf("3 + 9
    ");//10 24
                printf("4 - 5
    ");//11 0
                printf("11 * 6
    ");//12 0
                printf("12 * 7
    ");//13 0
                printf("13 * 8
    ");//14 0
                printf("14 + 10
    ");//15 24
            }
            else if(N == 9)
            {
                printf("1 + 2
    ");//10   18
                printf("10 + 3
    ");//11  27
                printf("11 * 4
    ");//12  243
                printf("12 / 5
    ");//13  27
                printf("6 + 7
    ");//14   18
                printf("14 + 8
    ");//15  27
                printf("15 / 9
    ");//16  3
                printf("13 - 16
    ");//17 24
            }
            else if(N == 10)
            {
                printf("1 + 2
    ");//11   20
                printf("3 + 4
    ");//12   20
                printf("12 + 5
    ");//13  30
                printf("13 + 6
    ");//14  40
                printf("14 / 7
    ");//15  4
                printf("11 + 15
    ");//16 24
                printf("8 - 9
    ");//17   0
                printf("17 / 10
    ");//18 0
                printf("16 + 18
    ");//19 24
            }
            else if(N == 11)
            {
                printf("1 + 2
    ");//12  22
                printf("12 / 3
    ");//13 2
                printf("13 + 4
    ");//14 13
                printf("14 + 5
    ");//15 24
                printf("15 + 6
    ");//16 35
                printf("16 + 7
    ");//17 46
                printf("17 + 8
    ");//18 57
                printf("18 - 9
    ");//19 46
                printf("19 - 10
    ");//20 35
                printf("20 - 11
    ");//21 24
            }
            else if(N >= 12 && N % 2 == 0)
            {
                printf("1 + 2
    ");//N+1                  2*N
                printf("%d + 3
    ",N+1);//N+2             3*N
                printf("4 + 5
    ");//N+3                  2*N
                printf("%d + 6
    ",N+3);//N+4             3*N
                printf("%d + 7
    ",N+4);//N+5             4*N
                printf("8 + 9
    ");//N+6                  2*N
                printf("%d / 10
    ",N+2);//N+7            3
                printf("%d / 11
    ",N+5);//N+8            4
                printf("%d / 12
    ",N+6);//N+9            2
                printf("%d * %d
    ",N+7,N+8);//N+10       12
                printf("%d * %d
    ",N+9,N+10);//N+11      24
                for(int i=0;i<(N-12)/2;i++)
                {
                    printf("%d + %d
    ",N+11+2*i,13+i*2);//N+12+2*i
                    printf("%d - %d
    ",N+12+2*i,14+i*2);//N+13+2*i
                }
            }
            else if(N>=13 && N % 2 == 1)
            {
                printf("1 + 2
    ");//N+1               2*N
                printf("%d + 3
    ",N+1);//N+2          3*N
                printf("4 + 5
    ");//N+3               2*N
                printf("%d + 6
    ",N+3);//N+4          3*N
                printf("%d + 7
    ",N+4);//N+5          4*N
                printf("%d + 8
    ",N+5);//N+6          5*N
                printf("%d + 9
    ",N+6);//N+7          6*N
                printf("%d + 10
    ",N+7);//N+8         7*N
                printf("%d + 11
    ",N+8);//N+9         8*N
                printf("%d / 12
    ",N+2);//N+10        3
                printf("%d / 13
    ",N+9);//N+11        8
                printf("%d * %d
    ",N+10,N+11);//N+12  24
                for(int i=0;i<(N-13)/2;i++)
                {
                    printf("%d + %d
    ",N+12+2*i,14+i*2);//N+13+2*i
                    printf("%d - %d
    ",N+13+2*i,15+i*2);//N+14+2*i
                }
    
            }
        }
    }



  • 相关阅读:
    Nginx的启动、停止与重启
    linux环境下安装nginx步骤
    关于Nginx的负载均衡
    【Nginx】实现动静分离
    nginx中的反向代理
    Nignx的简介
    ERROR 1822 (HY000): Failed to add the foreign key constraint. Missing index for constraint 'orderite
    mysql出现“ You can't specify target table '表名' for update in FROM clause”解决方法
    SpringMvc的工作原理图
    【Java多线程】Java中的13个原子操作类(十九)
  • 原文地址:https://www.cnblogs.com/jzssuanfa/p/6846293.html
Copyright © 2011-2022 走看看