CodeForces - 468A
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
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 题目大意:给你一个n,1-n当中每次选两个数进行运算,进行n-1次运算后要为24,并且用过的数不能再用,新算出的数可以接着用,打印任意一种情况。 思路:n小于4的一定不可以,n等于4和5需要特判,其他情况都可以转化为3-2=1,1-1=0开头,然后用0*i=0(i!=4&&i!=6),最后加个4*6=24就行了。
代码:
#include<stdio.h>
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
int n;
cin>>n;
if(n<)
cout<<"NO"<<endl;
else if(n==)
{
cout<<"YES"<<endl;
printf("1 * 2 = 2\n");
printf("2 * 3 = 6\n");
printf("4 * 6 = 24\n");
}
else if(n==)
{
cout<<"YES"<<endl;
printf("3 * 5 = 15\n");
printf("2 * 4 = 8\n");
printf("15 + 8 = 23\n");
printf("23 + 1 = 24\n");
}
else
{
cout<<"YES"<<endl;
printf("3 - 2 = 1\n");
printf("1 - 1 = 0\n");
printf("0 * 5 = 0\n");
for(int i=;i<=n;i++)
if(i!=&&i!=)
printf("0 * %d = 0\n",i);
printf("4 * 6 = 24\n");
printf("24 + 0 = 24\n");
}
return ;
}
CodeForces - 468A的更多相关文章
- codeforces 468A. 24 Game 解题报告
题目链接:http://codeforces.com/problemset/problem/468/A 题目意思:给出一个数n,利用 1 - n 这 n 个数,每个数只能用一次,能否通过3种运算: + ...
- CodeForces 468A Program F
Description Little X used to play a card game called "24 Game", but recently he has found ...
- [ An Ac a Day ^_^ ] CodeForces 468A 24 Game 构造
题意是让你用1到n的数构造24 看完题解感觉被样例骗了…… 很明显 n<4肯定不行 然后构造出来4 5的组成24的式子 把大于4(偶数)或者5(奇数)的数构造成i-(i-1)=1 之后就是无尽的 ...
- CodeForces - 468A ——(思维题)
Little X used to play a card game called "24 Game", but recently he has found it too easy. ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
随机推荐
- jquery运用FormData结合Ajax异步上传表单,超实用
首先创建一个formData,其中参数,就是你的form表单,jquery要加0,也可以用document.querySelector("form")得到 var formData ...
- Spring Boot 引入org.springframework.boot.SpringApplication出错
今天新建的一个spring boot maven项目, 写启动类时发现无法引入SpringApplication, 经查原来是冲突了,我早些时候用了比较低版本的spring boot创建了项目 ,导致 ...
- PHP的数据类型和魔术常量
一. 1.boolean 布尔类型 (布尔值本身,整型0,浮点型0.0,空字符串,不包含任何元素的数组,不包括任何成员变量的对象 NULL,未赋值的变量) 2.integer 整型 3.float 浮 ...
- lcr电桥浅谈
此图告知,现代的lcr电桥使用的都是虚地,阻抗很高. 系统采用的鉴相器比较简单,是检半个正弦基波(RMS有效值积分),可以有效抵御偶次基波. 倒不如直接使用运放电容移相,比较采样法直接采样最高点. 此 ...
- USACO1.4 1.5 搜索剪枝与数字 洛谷OJ P1214 P1215 P1217 P1218
USACO1.4 题解 Arithmetic Progressions 题意 让你求长为n的由小于2*m*m的双平方数组成的等差数列有几个 双平方数:形如 B=P*P+Q*Q,p,q>0的数 题 ...
- centos7安装nodejs运行环境及卸载
一.安装1.进入官网下载最新版本https://nodejs.org/en/ 选择下载后上传或直接使用wget下载 wget https://nodejs.org/dist/v8.11.2/node- ...
- 腾讯云CDB回档失败浅析
Ⅰ.先看问题 先简单介绍下cdb的回档功能,回档分为极速.快速.普通,分别对应指定表.指定库.整个实例回档. 控制台报错回档任务执行失败 提示信息:rollback table failed:SQL ...
- js除法四舍五入
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <hea ...
- 学习ActiveMQ(三):发布/订阅模式(topic)演示
1.在这个项目中新增两个java类,主题生产者和主题消费者: 2.和点对点的代码差别并不大,所以将消费者和生产者的分别代码拷入新增的java类中,再修改就好了. appProducerTopic代码: ...
- springcloud第八步:hystrix解决服务雪崩
断路器(Hystrix) 为什么需要 Hystrix? 在微服务架构中,我们将业务拆分成一个个的服务,服务与服务之间可以相互调用(RPC).为了保证其高可用,单个服务又必须集群部署.由于网络原因或者自 ...