A. 24 Game
来源:互联网 发布:知乎top50 编辑:程序博客网 时间:2024/06/06 02:17
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?
The first line contains a single integer n (1 ≤ n ≤ 105).
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 than1018. 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.
1
NO
8
YES8 * 7 = 566 * 5 = 303 - 4 = -11 - 2 = -130 - -1 = 3156 - 31 = 2525 + -1 = 24
解题说明:此题就是给出一列数算24,可以用暴力求解,构造一个最小集,然后其他的数字相减消去。
#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>#include<string>#include<cmath>#include<cstdlib>using namespace std;int main(){int n, i;scanf("%d", &n);if(n <= 3){printf("NO\n");return 0;}else{printf("YES\n");if(n % 2 == 0){printf("1 * 2 = 2\n");printf("2 * 3 = 6\n");printf("6 * 4 = 24\n");for(i = n; i >= 6; i -= 2){printf("%d - %d = 1\n", i, i-1);printf("24 * 1 = 24\n");}}else{printf("5 - 2 = 3\n");printf("3 - 1 = 2\n");printf("2 * 3 = 6\n");printf("4 * 6 = 24\n");for(i = n; i >= 7; i -= 2){printf("%d - %d = 1\n", i, i-1);printf("24 * 1 = 24\n");}}}return 0;}
- codeforces a 24 game
- A. 24 Game
- CF 468A 24 Game
- 【codeforces】 468A 24 Game
- CodeForces-468A-24 Game
- Codeforces 468A 24 Game
- CodeForces 468A A. 24 Game
- A Game
- A Game
- A. Game
- A. Game
- Making a mobile game in 24 hours
- codeforces-#468A. 24 Game(构造)
- 【构造】 Codeforces 468A 24 Game
- codeforces 468A 24 Game 构造
- cf 468A 24 Game 构造
- Codeforces 468A 24 Game(构造)
- CodeForces 468A 24 Game 规律题
- 李德馨 漢陰 道不可假
- 安卓 数据库的版本升级问题
- 对于十月的一个交代
- shell中$0,$?,$!等的特殊用法
- oracle的字符集(NLS_LANGUAGE)
- A. 24 Game
- Valid Parentheses- LeetCode
- jQuery Mobile 移动网站开发之日期控件Mobiscroll 2.5 使用说明
- BASE64算法
- uboot源码分析——启动linux内核
- Android 开发笔记
- web架构资料汇总
- USACO Betsy's Tour 解题报告
- android之底部导航