Codeforces Round #268 (Div. 2) C
来源:互联网 发布:淘宝女童模特章露雅 编辑:程序博客网 时间:2024/05/16 23:32
题目:
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 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.
1
NO
8
YES8 * 7 = 566 * 5 = 303 - 4 = -11 - 2 = -130 - -1 = 3156 - 31 = 2525 + -1 = 24
题意分析:
代码:
#include <cstdio>#include <algorithm>#include <cstring>#include <cmath>#include <iostream>using namespace std;int main(){ int n,temp; while(scanf("%d",&n)!=EOF) { if(n<=3) { printf("NO\n"); continue; } printf("YES\n"); if(n%2==0) { temp=(n-4)/2; int t=n; for(int i=1;i<=temp;i++) { printf("%d - %d = 1\n",t,t-1); t-=2; } printf("4 * 2 = 8\n"); printf("1 * 3 = 3\n"); printf("8 * 3 = 24\n"); for(int i=0;i<temp;i++) printf("24 * 1 = 24\n"); } if(n%2==1) { temp=(n-5)/2; int t=n; for(int i=1;i<=temp;i++) { printf("%d - %d = 1\n",t,t-1); t-=2; } printf("5 - 1 = 4\n"); printf("4 - 2 = 2\n"); printf("2 * 4 = 8\n"); printf("8 * 3 = 24\n"); for(int i=0;i<temp;i++) printf("24 * 1 = 24\n"); } } return 0;}
- Codeforces Round #268 (Div. 2) C
- 【codeforces】Codeforces Round #370 (Div. 2) C
- Codeforces Round #268 (Div. 2)
- Codeforces Round #268 (Div. 2)
- Codeforces Round #268 (Div. 2)
- Codeforces Round #268 (Div. 2)
- Codeforces Round#268(Div 2)C 24 Game
- Codeforces Round #268 (Div. 2) C 24 Game [构造]
- Codeforces Round #268 (Div. 2) C 24 Game
- Codeforces Round #105 (Div. 2) C
- Codeforces Round 134 div 2 C题
- Codeforces Round #137 (Div. 2), problem: (C)
- Codeforces Round #153 (Div. 2) C题
- Codeforces Round #158 (Div. 2) C题
- Codeforces Round #162 (Div. 2) C
- Codeforces Round #166 (Div. 2) c. Secret
- Codeforces Round#170(Div 2)C
- Codeforces Round #173 (Div. 2) Problem C
- Spring 获取web根目录 (Spring线程获取web目录/路径/根目录,普通类获取web目录)
- DOS,WINDOWS递归删除指定文件夹或文件
- Codeforces Round #268 (Div. 1) A
- ubuntu上安装lamp
- Android应用安全实践 -- 某些Android应用在客户端明文存储登录密码
- Codeforces Round #268 (Div. 2) C
- 2014 ACM/ICPC Asia Regional Guangzhou Online HDU 5024 Wang Xifeng's Little Plot
- CF 268C 24 Game
- C语言中的零长度数组使用说明
- HTML5推箱子机理实现
- 数据结构(C实现)------- 链栈
- OpenSSL RSA 用法
- 谈谈C++类型安全
- AOP技术应用和研究