CodeForces 468A Program F
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 ≤ 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: "aopb = 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
NO
8
YES
8 * 7 = 56
6 * 5 = 30
3 - 4 = -1
1 - 2 = -1
30 - -1 = 31
56 - 31 = 25
25 + -1 = 24
- using namespace std;
- int main()
- {
- int n;
- while(~scanf("%d",&n))
- {
- if (n < 4)
- {
- printf("NO");
- continue;
- }
- printf("YES\n");
- if (n&1)//奇数
- {
- printf("3 + 4 = 7\n");
- printf("7 + 5 = 12\n");
- printf("12 * 2 = 24\n");
- printf("24 * 1 = 24\n");
- }
- else
- {
- printf("1 * 2 = 2\n");
- printf("2 * 3 = 6\n");
- printf("6 * 4 = 24\n");
- }
- for (int i = n; i > 5; i -= 2)//全部转化为1
- {
- printf("%d - %d = 1\n",i,i-1);
- printf("24 * 1 = 24\n");
- }
- }
- return 0;
- }
CodeForces 468A Program F的更多相关文章
- Codeforces #541 (Div2) - F. Asya And Kittens(并查集+链表)
Problem Codeforces #541 (Div2) - F. Asya And Kittens Time Limit: 2000 mSec Problem Description Inp ...
- Educational Codeforces Round 40 F. Runner's Problem
Educational Codeforces Round 40 F. Runner's Problem 题意: 给一个$ 3 * m \(的矩阵,问从\)(2,1)$ 出发 走到 \((2,m)\) ...
- codeforces Gym 100187F F - Doomsday 区间覆盖贪心
F. Doomsday Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/problem/F ...
- Codeforces gym 100685 F. Flood bfs
F. FloodTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100685/problem/F Desc ...
- Codeforces Gym 100513F F. Ilya Muromets 线段树
F. Ilya Muromets Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100513/probl ...
- Educational Codeforces Round 61 F 思维 + 区间dp
https://codeforces.com/contest/1132/problem/F 思维 + 区间dp 题意 给一个长度为n的字符串(<=500),每次选择消去字符,连续相同的字符可以同 ...
- Educational Codeforces Round 51 F. The Shortest Statement(lca+最短路)
https://codeforces.com/contest/1051/problem/F 题意 给一个带权联通无向图,n个点,m条边,q个询问,询问两点之间的最短路 其中 m-n<=20,1& ...
- Codeforces Gym 100513F F. Ilya Muromets 水题
F. Ilya Muromets Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100513/probl ...
- Educational Codeforces Round 12 F. Four Divisors 求小于x的素数个数(待解决)
F. Four Divisors 题目连接: http://www.codeforces.com/contest/665/problem/F Description If an integer a i ...
随机推荐
- HttpURLConnection请求接口
import java.io.BufferedInputStream; import java.io.BufferedReader; import java.io.DataOutputStream; ...
- find和xargs
find 命令的一般形式为 find pathname -options [-print -exec -ok] 让我们来看看该命令的参数: pathname find命令所查找的目录路径.例如用.来表 ...
- HMM隐马尔科夫模型
这是一个非常重要的模型,凡是学统计学.机器学习.数据挖掘的人都应该彻底搞懂. python包: hmmlearn 0.2.0 https://github.com/hmmlearn/hmmlearn ...
- RemoteWebDriver管理
直接贴代码: @Parameters({"BrowserType","NodeIP","NodePort"}) public void be ...
- 能源项目xml文件标签释义--CommonsMultipartResolver
<!-- 文件上传表单的视图解析器 --><bean id="multipartResolver" class="org.springframework ...
- 创建SSTP VPN,适应win7, 控制台导入证书
1. 按 视窗+r 打开运行,运行 mmc命令 2.打开控制台窗口 3.在默认界面 按 Ctrl+m 快捷键 打开添加单元 窗口,然后在其左侧列表双击 证书 项 4.在打开的证书管理单元 第一步中选择 ...
- JAVA类与对象作业——动手动脑以及课后实验性问题
一: 1.源代码 //MAO2015.10.6 //foo class Foo { int value; public Foo(int initValue) { value = initValue; ...
- hdu 3948 Portal (kusral+离线)
Portal Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Subm ...
- Android实现Activity页面跳转切换动画特效
了解Android程序设计的人应该知道,在Android 2.0之后有了overridePendingTransition(),其中里面两个参数,一个是前一个activity的退出,另一个activi ...
- JS实现漂亮的窗口拖拽效果(可改变大小、最大化、最小化、关闭)
转自<JS实现漂亮的窗口拖拽效果(可改变大小.最大化.最小化.关闭)>:http://www.jb51.net/article/73157.htm 这篇文章主要介绍了JS实现漂亮的窗口 ...