题目链接: 传送门

24 Game

time limit per test:1 second     memory limit per test:256 megabytes

Description

Little X used to play a card game called "24 Game", but recently he has found it too easy. So he invented a new game.
Initially you have a sequence of n integers: 1, 2, ..., n. In a single step, you can pick two of them, let's denote them a and b, erase them from the sequence, and append to the sequence either a + b, or a - b, or a × b.
After n - 1 steps there is only one number left. Can you make this number equal to 24?

Input

The first line contains a single integer n (1 ≤ n ≤ 10^5).

Output

If it's possible, print "YES" in the first line. Otherwise, print "NO" (without the quotes).
If there is a way to obtain 24 as the result number, in the following n - 1 lines print the required operations an operation per line. Each operation should be in form: "a op b = c". Where a and b are the numbers you've picked at this operation; op is either "+", or "-", or "*"; c is the result of corresponding operation. Note, that the absolute value of c mustn't be greater than 1018. The result of the last operation must be equal to 24. Separate operator sign and equality sign from numbers with spaces.
If there are multiple valid answers, you may print any of them.

Sample Input

1

8

Sample Output

NO

YES
8 * 7 = 56
6 * 5 = 30
3 - 4 = -1
1 - 2 = -1
30 - -1 = 31
56 - 31 = 25
25 + -1 = 24

解题思路:

题目大意:给一个数n,问能不能由1~n通过加减乘除组成24
解题思路:If n ≤ 3, it's easy to find that it's impossible to make 24, because the maximal number they can form is 9.
If n > 5, we can simply add n - (n - 1) = 1, 24  1 = 24 at the end of the solution to the number n - 2.
So we can find the solution of 4, 5 by hand. 1 
 2  3  4 = 24, (5 - 3)  4  (2 + 1) = 24
另外,在n > 5时,可以通过1+5 = 6,6-6=0,0x = 0,再由23*4=24.

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

int main()
{
    int N;
    while (~scanf("%d",&N))
    {
        if (N < 4)
        {
            printf("NO\n");
            continue;
        }
        if (N == 4)
        {
            printf("YES\n");
            printf("1 * 2 = 2\n");
            printf("2 * 3 = 6\n");
            printf("4 * 6 = 24\n");
        }
        else if (N == 5)
        {
            printf("YES\n");
            printf("5 - 3 = 2\n");
            printf("2 + 1 = 3\n");
            printf("2 * 3 = 6\n");
            printf("6 * 4 = 24\n");
        }
        else if (N > 5)
        {
            printf("YES\n");
            printf("5 + 1 = 6\n");
            printf("6 - 6 = 0\n");
            for (int i = 7;i <= N;i++)
            {
                printf("0 * %d = 0\n",i);
            }
            printf("2 + 0 = 2\n");
            printf("2 * 3 = 6\n");
            printf("6 * 4 = 24\n");
        }
    }
    return 0;
}

CF 468A 24 Game的更多相关文章

  1. codeforces 468A. 24 Game 解题报告

    题目链接:http://codeforces.com/problemset/problem/468/A 题目意思:给出一个数n,利用 1 - n 这 n 个数,每个数只能用一次,能否通过3种运算: + ...

  2. [ An Ac a Day ^_^ ] CodeForces 468A 24 Game 构造

    题意是让你用1到n的数构造24 看完题解感觉被样例骗了…… 很明显 n<4肯定不行 然后构造出来4 5的组成24的式子 把大于4(偶数)或者5(奇数)的数构造成i-(i-1)=1 之后就是无尽的 ...

  3. 译文 - Recommender Systems: Issues, Challenges, and Research Opportunities

    REF: 原文 Recommender Systems: Issues, Challenges, and Research Opportunities Shah Khusro, Zafar Ali a ...

  4. Hadoop+HBase 集群搭建

    Hadoop+HBase 集群搭建 1. 环境准备 说明:本次集群搭建使用系统版本Centos 7.5 ,软件版本 V3.1.1. 1.1 配置说明 本次集群搭建共三台机器,具体说明下: 主机名 IP ...

  5. https传输过程嗅探

    C1->浏览器告知服务器自身的信息 length = 165 a5 16 03 01 00 A0 01 00 00 9C 03 03 5E 1C 37 CD 40 [ ^ 7 @] B6 4A ...

  6. hBase官方文档以及HBase基础操作封装类

    HBase 官方文档 0.97 http://abloz.com/hbase/book.html HBase基本操作封装类(以课堂爬虫为例) package cn.crxy.spider.utils; ...

  7. hbase 增删改查 api 简单操作

    package com.utils; import java.io.IOException; import java.util.ArrayList; import java.util.List; im ...

  8. python3.7+flask+alipay 支付宝付款功能

    文档参考github:https://github.com/fzlee/alipay/blob/master/docs/init.md 沙箱环境配置:https://opendocs.alipay.c ...

  9. [ 9.24 ]CF每日一题系列—— 468A构造递推

    Description: 1 - n个数问你能否经过加减乘除这些运算n -1次的操作得到24 Solutrion: 一开始想暴力递推,发现n的范围太大直接否决,也否决了我的跑dfs,后来就像肯定有个递 ...

随机推荐

  1. FineUI(专业版)高清大图赏析!(第二波)

    FineUI(专业版)是由三生石上全新打造的基于 jQuery 的专业 ASP.NET 控件库,计划在七月下旬正式发布. 选择FineUI(专业版)的四大理由:1. 简单:专业版和开源版兼容(v4.x ...

  2. mSites and Smarty

    目前的页面实现方式是需要向后台请求接口,返回 JSON 数据,动态拼接字符串塞进 DOM 中(innerHTML).考虑用 Smarty 生成静态页面,可以在后台用 PHP 得到数据,字符串拼接,然后 ...

  3. checkboxlist 下拉框多选功能 ,模拟dropdownlist带复选框效果

    前台代码 01.<html xmlns="http://www.w3.org/1999/xhtml"> 02.<head runat="server&q ...

  4. 171 Excel Sheet Column Number

    /** * 题意:A表示1 B表示2 AA表示27 AB表示28 ------>给你一串字符串输出相应的数字 * 分析:这个就类似于二进制转十进制,从字符串后面往前遍历,然后pow(26,n)* ...

  5. 项目分布式部署那些事(1):ONS消息队列、基于Redis的Session共享,开源共享

    因业务发展需要现在的系统不足以支撑现在的用户量,于是我们在一周之前着手项目的性能优化与分布式部署的相关动作. 概况 现在的系统是基于RabbitHub(一套开源的开发时框架)和Rabbit.WeiXi ...

  6. BroadcastReceiver之SD的挂载监听

    首先,新建一个类,继承于BroadcastReceiver,然后去配置Manifest.xml这就不用说了, 注意配置Manifest.xml时候的一些细节 必须加上<data android: ...

  7. SVG的使用

    一,svg可以在浏览器中直接打开 二,在html使用<img/>标签引用 三,直接在html中使用svg标签 四,作为css背景 SVG支持ie9+ ,chrome 33.0+,firef ...

  8. mysql 根据某些字段之和排序

    在自己项目中记录了比赛球队获得金银铜牌的具体奖牌数,遇到需求是按照奖牌个数排序 select a.RANK_ID,a.COUNTRY,a.GOLD,a.SILVER,a.BRONZE,a.ICON,a ...

  9. [转]oracle数据类型和对应的java类型

    地址: http://otndnld.oracle.co.jp/document/products/oracle10g/102/doc_cd/java.102/B19275-03/datacc.htm ...

  10. Shell脚本_启动停止重启sh脚本

    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 3 ...