原题链接:http://codeforces.com/problemset/problem/468/A

24 Game

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 ≤ 105).

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.

Examples
input

1

output

NO

input

8

output

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

题解

一道简单题。

1,2,31,2,31,2,3肯定不行,考虑到后面相邻的数两两相减就是111,乘的话对答案没有影响,所以们只需要手动把前几个数凑成24" role="presentation" style="position: relative;">242424,后面一直乘111就行了。

于是我们可以这么凑:

当n" role="presentation" style="position: relative;">nnn为偶数时:

1×2×3×4=241×2×3×4=24

1\times 2\times 3\times 4=24

当nnn为奇数时:

1+2×4+3×5=24" role="presentation" style="text-align: center; position: relative;">1+2×4+3×5=241+2×4+3×5=24

1+2\times 4+3\times 5=24

大功告成。

代码
#include<bits/stdc++.h>
using namespace std;
int n;
void in(){scanf("%d",&n);}
void ac()
{if(n<4){puts("NO");return;}puts("YES");if(n&1){printf("2 * 4 = 8\n3 * 5 = 15\n8 + 15 = 23\n23 + 1 = 24\n");for(int i=6;i<n;i+=2)printf("%d - %d = 1\n24 * 1 = 24\n",i+1,i);return;}printf("1 * 2 = 2\n2 * 3 = 6\n6 * 4 = 24\n");for(int i=5;i<n;i+=2)printf("%d - %d = 1\n24 * 1 = 24\n",i+1,i);
}
int main(){in();ac();}

CF468A 24 Game相关推荐

  1. 混合装置实现了24/7的能量收集和储存

    混合装置实现了24/7的能量收集和储存 Hybrid device achieves 24/7 energy harvesting and storage 休斯顿大学的研究人员设计了一种能有效捕捉太阳 ...

  2. Python七大原则,24种设计模式

    七大设计原则: 1.单一职责原则[SINGLE RESPONSIBILITY PRINCIPLE]:一个类负责一项职责.  2.里氏替换原则[LISKOV SUBSTITUTION PRINCIPLE ...

  3. 零起点学算法24——求正弦和余弦

    零起点学算法24--求正弦和余弦 Time Limit: 1 Sec  Memory Limit: 64 MB   64bit IO Format: %lld Description 输入一个正整数n ...

  4. Static interface methods are only supported starting with Android N (--min-api 24): void okhttp3.log

    错误内容如下 Error: Static interface methods are only supported starting with Android N (--min-api 24): vo ...

  5. 24点c语言程序,C语言解24点游戏程序

    该楼层疑似违规已被系统折叠 隐藏此楼查看此楼 前几天在微博上看到24点的游戏,6 6 6 10.算了很久是在算不出来,最后我想我何不写一个小程序解决它?说做就做,我刚开始的想法很简单,就是列举4个数的 ...

  6. rpm方式安装mysql5.7.24_linux centOS 7安装mysql 5.7.24

    前言 请务必先把整篇文章通读一遍,特别是后面的问题列表,以致于在安装过程中出现问题后不会心惊胆颤. 0.在安装mysql之前,查看是否已安装,及其删除方式 rpm -qa|grep mysql #查看 ...

  7. 24核服务器配什么系统,24核服务器

    24核服务器 内容精选 换一换 安装昇腾芯片驱动和固件之前需验证操作系统内核版本.请参考下表完成操作系统内核版本的验证以及驱动固件的安装. 华为TaiShan服务器在数据库场景具有高可靠和稳定性,多核 ...

  8. centos 7 mysql界面管理器_centos7安装mysql5.7.24,并使用system管理mysql

    1.创建安装目录 mkdir /mysql 2.进入安装目录 cd /data 3.下载5.7.24的tar包 wget https://downloads.mysql.com/archives/ge ...

  9. 2021年广东省高考英语听说成绩查询,广东2021年高考准考证今起自行打印 成绩及分数线6月24日左右公布...

    再过3天,就是2021年全国高考的日子了.据悉,今年全国高考报名1078万人,再创历史新高.与此同时,各省教育考试院也有条不紊地备战高考. 近日,广东省教育考试院发布6月招考日历,其中提到2021年广 ...

  10. 优达学城《DeepLearning》2-4:自编码器(无监督学习算法)

    本次包含3个部分: 简单的自编码器 卷积自编码器 去噪自编码器 目录 1 简单的自编码器 压表示法缩 可视化数据 线性自编码器 训练 检查结果 2 卷积自编码器 Encoder Decoder 解码器 ...

最新文章

  1. cartograhper--X1_lidar
  2. python手机版安卓-当python遇到Android手机 那么,万物皆可盘
  3. Android Telephony分析(七) ---- 接口扩展(异步转同步)
  4. java forname 原理_Java Class.forName()用法和newInstance()方法原理解析
  5. 通过视频着色进行自监督跟踪
  6. linux pcie命令,setpci命令_Linux setpci 命令用法详解:查询和配置PCI设备的使用工具...
  7. Android SpannableString
  8. Setup Factory 打包工具部分功能代码解
  9. Git钩子:自定义你的工作流
  10. 超酷的屏幕抠图转场技巧
  11. 通信软件开发与应用结业报告
  12. 2019 第十届蓝桥杯Java省赛B组个人题解
  13. 【uniapp城市三级联动】包含完整代码-城市三级联动json
  14. youtube-dl 环境搭建 使用
  15. Borůvka算法与异或生成树
  16. 小白刷LeeCode(算法篇):4
  17. 无root权限怎么完全卸载系统自带软件(捆绑软件)
  18. 谷歌地球的高清卫星影像数据都来源自哪里?用户如何下载谷歌影像?
  19. android5.0新特性 clipping的用法
  20. 2012年第三届C/C++ B组蓝桥杯省赛真题

热门文章

  1. WinPmem:跨平台内存采集工具
  2. Android studio 报错 Gradle sync failed 你的主机中的软件中止了一个已建立的连接
  3. 查询字符串中子字符串所有出现位置
  4. 20180810 多益网络模拟笔试
  5. LVS(三)LVS集群NAT模式
  6. 高质量程序设计指南c++/c语言(19)--赋值操作符“=”
  7. django基础入门(3)django中模板
  8. 计算一条3d空间直线和一个3d空间平面的交点
  9. Docker 安装 maven 私服
  10. MyBatis源码阅读(二) --- 执行流程分析