cf468A 24 Game
1 second
256 megabytes
standard input
standard output
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
YES
8 * 7 = 56
6 * 5 = 30
3 - 4 = -1
1 - 2 = -1
30 - -1 = 31
56 - 31 = 25
25 + -1 = 24
其实就是sb题
注意到每4个数可以消掉
n<4直接打出NO
n=4到7打表
大于7的对4取mod之后各种乱搞
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<ctime>
#include<set>
#define LL long long
using namespace std;
inline LL read()
{
LL x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
int n;
int main()
{
scanf("%d",&n);
if (n<4){printf("NO\n");return 0;}
int s;
if(n%4==0)printf("YES\n1 * 2 = 2\n2 * 3 = 6\n6 * 4 = 24\n"),s=n-4;
else if (n%4==1)printf("YES\n4 * 5 = 20\n20 + 2 = 22\n22 + 3 = 25\n25 - 1 = 24\n"),s=n-5;
else if (n%4==2)printf("YES\n5 * 6 = 30\n30 - 4 = 26\n26 - 3 = 23\n23 - 1 = 22\n22 + 2 = 24\n"),s=n-6;
else if (n%4==3)printf("YES\n7 + 6 = 13\n13 + 5 = 18\n18 + 4 = 22\n22 + 3 = 25\n25 - 2 = 23\n23 + 1 = 24\n"),s=n-7;
for(int j=n-s+1;j<=n;j+=2)
printf("%d - %d = 1\n",j+1,j);
for (int j=1;j<=s/4;j++)
printf("1 - 1 = 0\n");
for (int j=1;j<=s/4;j++)
printf("24 + 0 = 24\n");
}
cf468A 24 Game的更多相关文章
- CF468A | 24 Game 找规律+打表
(翻译版本来自 Luogu by lonelysir ) 题目描述 小X一直很喜欢一个纸牌游戏:"24点",但最近他发现这个游戏太简单了,所以他发明了一个新游戏. 你有一个整数序列 ...
- Fedora 24中的日志管理
Introduction Log files are files that contain messages about the system, including the kernel, servi ...
- CSharpGL(24)用ComputeShader实现一个简单的图像边缘检测功能
CSharpGL(24)用ComputeShader实现一个简单的图像边缘检测功能 效果图 这是红宝书里的例子,在这个例子中,下述功能全部登场,因此这个例子可作为使用Compute Shader的典型 ...
- 【趣味分享】C#实现回味童年的24点算法游戏
一.24点游戏玩法规则效果展示 1.初始化界面 2.开始游戏界面 3.游戏超时界面 4.查看答案界面 5.答对界面 6.答错界面 7.计算表达式的验证界面 8.一副牌算完开始新一副牌界面 到这里24点 ...
- C#开发微信门户及应用(24)-微信小店货架信息管理
在前面微信小店系列篇<C#开发微信门户及应用(22)-微信小店的开发和使用>里面介绍了一些微信小店的基础知识,以及<C#开发微信门户及应用(23)-微信小店商品管理接口的封装和测试& ...
- [MySQL Reference Manual] 24 MySQL sys框架
24 MySQL sys框架 24 MySQL sys框架 24.1 sys框架的前提条件 24.2 使用sys框架 24.3 sys框架进度报告 24.4 sys框架的对象 24.4.1所有sys下 ...
- mysql 5.6.24安装实例
安装前准备工作: 1)编辑PATH路径 vim /etc/profile PATH=/home/mysql/bin:/home/mysql/lib:$PATH export PATH 2)生效PATH ...
- C语言-纸牌计算24点小游戏
C语言实现纸牌计算24点小游戏 利用系统时间设定随机种子生成4个随机数,并对4个数字之间的运算次序以及运算符号进行枚举,从而计算判断是否能得出24,以达到程序目的.程序主要功能已完成,目前还有部分细节 ...
- .NET开发人员必看:提高ASP.NET Web应用性能的24种方法和技巧
那性能问题到底该如何解决?以下是应用系统发布前,作为 .NET 开发人员需要检查的点. 1.debug=「false」 当创建 ASP.NET Web应用程序,默认设置为「true」.开发过程中,设置 ...
随机推荐
- DeflateStream类
DeflateStream是另外一种压缩与解压缩流,使用方法与GZipStream类似,而且压缩之后的带下也差不多. 一.属性 BaseStream 获取对基础流的引用. CanRead 获取一个值 ...
- Linux的环境变量配置
以下都是环境变量相关的配置文件 1)/etc/enviroment 是系统的环境变量. (2)/etc/profile: 是所有用户的环境变量.当用户第一次登录时,该文件被执行. 并从/etc/pro ...
- [一步一步MVC]第二回:还是ActionFilter,实现对业务逻辑的统一Authorize处理 OnActionExecuting内如何获取参数
如何获取参数:http://www.cnblogs.com/anytao/archive/2009/04/23/anytao-mvc-02-actionauthorize.html 由问题引出 在AS ...
- 剑指offer-面试题16.反转链表
题目:定义一个函数,输入一个链表的头结点,反转该链表并输出反转后的头结点 链表结点定义如下: struct ListNode { int m_nKey; ListNode* m_pNext; } 其实 ...
- 关于set和map的用法
1.set 定义:每个元素最多只出现一次,并且默认的是从小到大排序. set 遍历: 题目http://www.cnblogs.com/ZP-Better/p/4700218.html for(set ...
- 【转】android电池(五):电池 充电IC(PM2301)驱动分析篇
关键词:android 电池 电量计 PL2301任务初始化宏 power_supply 中断线程化 平台信息:内核:linux2.6/linux3.0系统:android/android4.0 ...
- VMware 虚拟机的网络连接方式详解
VMWare提供了三种工作模式,它们是bridged(桥接模式).NAT(网络地址转换模式)和host-only(主机模式).要想在网络管理和维护中合理应用它们,你就应该先了解一下这三种工作 ...
- #include<string.h>
#include<string.h> 1 strcpy #include <string.h> char *strcpy(char *str1, const char *str ...
- textField 判断输入长度限制
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementS ...
- hive优化之自己主动合并输出的小文件
1.先在hive-site.xml中设置小文件的标准. <property> <name>hive.merge.smallfiles.avgsize</name> ...