A. 24 Game

Time Limit: 1 Sec

Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/468/problem/A

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: "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.

Sample Input

8

Sample Output

YES
8 * 7 = 56
6 * 5 = 30
3 - 4 = -1
1 - 2 = -1
30 - -1 = 31
56 - 31 = 25
25 + -1 = 24

HINT

题意

给你1到n,的n个数,你可以挑选两个数出来进行加减乘除,然后再把这俩数擦去,然后再把新得到的数扔进去,问你最后剩下的数是不是24

题解:

构造题,小于三个肯定不行了,因为乘起来才12……

大于等于4个就可行了,因为1*2*3*4 = 24,后面的数都相减为1 就好了

奇数也可以构造 (3-1)*2*5+4=24,然后后面的数都减1就好了

代码:

//qscqesze
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <bitset>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 100006
#define mod 1000000007
#define eps 1e-9
#define PI acos(-1)
const double EP = 1E- ;
int Num;
//const int inf=0x7fffffff;
const ll inf=;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
//************************************************************************************* int main()
{
int n=read();
if(n<)cout<<"NO"<<endl;
else
{
cout<<"YES"<<endl;
for(;n->=;n-=)
cout<<n<<" - "<<n-<<" = 1\n1 * 1 = 1\n";
if(n==)
{
cout<<"1 * 2 = 2"<<endl;
cout<<"2 * 3 = 6"<<endl;
cout<<"6 * 4 = 24"<<endl;
}
else
{
cout<<"3 - 1 = 2"<<endl;
cout<<"2 * 2 = 4"<<endl;
cout<<"4 * 5 = 20"<<endl;
cout<<"20 + 4 = 24"<<endl;
}
}
}

Codeforces Round #268 (Div. 1) A. 24 Game 构造的更多相关文章

  1. Codeforces Round #268 (Div. 2) ABCD

    CF469 Codeforces Round #268 (Div. 2) http://codeforces.com/contest/469 开学了,时间少,水题就不写题解了,不水的题也不写这么详细了 ...

  2. Codeforces Round #275 (Div. 1)A. Diverse Permutation 构造

    Codeforces Round #275 (Div. 1)A. Diverse Permutation Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 ht ...

  3. Codeforces Round #268 (Div. 2)

    补题解: E:只会第四种解法:也只看懂了这一种. PS:F[X+10^18]=F[X]+1;F[X]表示X的数字之和; 假设X,F[10^18+X]+F[10^18+X-1]+......F[10^1 ...

  4. Codeforces Round #268 (Div. 1) B. Two Sets 暴力

    B. Two Sets Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/468/problem/B ...

  5. 贪心+bfs 或者 并查集 Codeforces Round #268 (Div. 2) D

    http://codeforces.com/contest/469/problem/D 题目大意: 给你一个长度为n数组,给你两个集合A.B,再给你两个数字a和b.A集合中的每一个数字x都也能在a集合 ...

  6. Codeforces Round #268 (Div. 2) (被屠记)

    c被fst了................ 然后掉到600+.... 然后...估计得绿名了.. sad A.I Wanna Be the Guy 题意:让你判断1-n个数哪个数没有出现.. sb题 ...

  7. Codeforces Round #268 (Div. 1) 468D Tree(杜教题+树的重心+线段树+set)

    题目大意 给出一棵树,边上有权值,要求给出一个1到n的排列p,使得sigma d(i, pi)最大,且p的字典序尽量小. d(u, v)为树上两点u和v的距离 题解:一开始没看出来p需要每个数都不同, ...

  8. Codeforces Round #268 (Div. 2) D. Two Sets [stl - set + 暴力]

    8161957                 2014-10-10 06:12:37     njczy2010     D - Two Sets             GNU C++     A ...

  9. Codeforces Round #342 (Div. 2) C. K-special Tables 构造

    C. K-special Tables 题目连接: http://www.codeforces.com/contest/625/problem/C Description People do many ...

随机推荐

  1. fiddler代理

    对于前段开发人员,fiddler 是一个必不可少的调试神器.下载地址:http://www.telerik.com/download/fiddler. 有同学也许会碰到,chrome 下 fiddle ...

  2. C++ 空类默认产生成员函数

    class Empty { Empty(){...} //默认构造函数 ~Empty(){...} //默认析构函数 Empty(const Empty&){...} //拷贝构造函数 Emp ...

  3. 大四实习准备2_java异常处理_android控件练习

    2015-4-24 Java 异常处理 可以有多个catch;ArrayIndexOutOfBoundsException类是Exception类的子类RuntimeException类的一个间接子类 ...

  4. UVa 808 (建坐标系、找规律) Bee Breeding

    题意: 如图,按照图中的规律给这些格子编号.给出两个格子的编号,求从一个格子到另一个格子的最少步数.(一步只能穿过有有公共边的格子) 分析: 根据高中数学知识,选任意两个不共线的向量,就能表示平面上所 ...

  5. APIO2010特别行动队(单调队列、斜率优化)

    其实这题一看知道应该是DP,再一看数据范围肯定就是单调队列了. 不过我还不太懂神马单调队列.斜率优化…… 附上天牛的题解:http://www.cnblogs.com/neverforget/arch ...

  6. 嵌入式linux市场份额

    来自华清远见2014年度的调查统计数据显示,在嵌入式产品研发的软件开发平台的选择上,嵌入式Linux以55%的市场份额遥遥领先于其他嵌入式开发软件发平台,比去年增长了13个百分比,这已经是连续4年比例 ...

  7. [swustoj 1095] 挖金子

    挖金子(1095) 题目描述 你在一个N*M的区域中,一开始在(1,1)的位置,每个位置有可能有金子,也有可能不能到达,也有可能有传送门.你只能往右或者下走,不能走出这个区域.当你位于传送门时,传送门 ...

  8. Spring Data JPA初使用

    我们都知道Spring是一个非常优秀的JavaEE整合框架,它尽可能的减少我们开发的工作量和难度. 在持久层的业务逻辑方面,Spring开源组织又给我们带来了同样优秀的Spring Data JPA. ...

  9. Today I Cooked the Sun Yat-Sen University [2007-09-25 12:37:39]

    Aha,yes,it is! And I paticipate in the school page of sysu...and cann't change my previous csu to sy ...

  10. POJ3087 Shuffle'm Up 简单模拟

    题意:就是给你两副扑克,然后一张盖一张洗牌,不断重复这个过程,看能不能达到目标的扑克顺序 分析:然后就模拟下,-1的情况就是有循环节 #include<cstdio> #include&l ...