Codeforces Round #268 (Div. 1) A. 24 Game 构造
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 构造的更多相关文章
- Codeforces Round #268 (Div. 2) ABCD
CF469 Codeforces Round #268 (Div. 2) http://codeforces.com/contest/469 开学了,时间少,水题就不写题解了,不水的题也不写这么详细了 ...
- 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 ...
- 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 ...
- 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 ...
- 贪心+bfs 或者 并查集 Codeforces Round #268 (Div. 2) D
http://codeforces.com/contest/469/problem/D 题目大意: 给你一个长度为n数组,给你两个集合A.B,再给你两个数字a和b.A集合中的每一个数字x都也能在a集合 ...
- Codeforces Round #268 (Div. 2) (被屠记)
c被fst了................ 然后掉到600+.... 然后...估计得绿名了.. sad A.I Wanna Be the Guy 题意:让你判断1-n个数哪个数没有出现.. sb题 ...
- Codeforces Round #268 (Div. 1) 468D Tree(杜教题+树的重心+线段树+set)
题目大意 给出一棵树,边上有权值,要求给出一个1到n的排列p,使得sigma d(i, pi)最大,且p的字典序尽量小. d(u, v)为树上两点u和v的距离 题解:一开始没看出来p需要每个数都不同, ...
- Codeforces Round #268 (Div. 2) D. Two Sets [stl - set + 暴力]
8161957 2014-10-10 06:12:37 njczy2010 D - Two Sets GNU C++ A ...
- 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 ...
随机推荐
- Complete The Pattern #1
Complete The Pattern #1 Task: You have to write a function pattern which creates the following patte ...
- Scrapy在win7 32位的安装及依赖包
Scrapy,一个网络爬虫的框架,首先第一步肯定是安装. 参考网上的文章. 安装过程中需要用到pip工具,请自行安装. 1.安装python 这个是必须的,既然都用到scrapy了,肯定已经安装了py ...
- 'ascii' codec can't encode characters in position 0-8: ordinal not in range(128)的解决办法
使用的python2.7,运行的时候出现了'ascii' codec can't encode characters in position 0-8: ordinal not in range(128 ...
- 基于邻接矩阵的广度优先搜索遍历(BFS)
题目:http://acm.sdut.edu.cn/sdutoj/showproblem.php?pid=2141&cid=1186 #include<stdio.h> #incl ...
- WindowsPhone8SDK重装后设计器加载异常的处理办法
Close all running instances of Visual Studio 2012 start cmd.exe (as admin/elevated) cd /d %windir%\i ...
- (六)学习CSS之color属性
参考:http://www.w3school.com.cn/cssref/pr_text_color.asp color 属性规定文本的颜色. 这个属性设置了一个元素的前景色(在 HTML 表现中,就 ...
- 一个简单的appium脚本
这是一个简单的appium脚本,测试amazon购物过程的,过程包括搜索商品,然后从结果列表中选取中意的商品,然后加入购物车,等等. 它是一个最原始的脚本,对测试元素.数据.报告等未作任何的封装,后面 ...
- Android的有关EditText的能多行显示但无法禁止自动换行的Bug!
需求: 使 EditText或TextView 支持 多行显示,但是不自动换行,即能水平滚动较长的内容. Bug: 想当然的,在XML定义中设置如下,应该就可以了. android:scrollHor ...
- 设计模式_Visitor_访问者模式
形象例子: 情人节到了,要给每个MM送一束鲜花和一张卡片,可是每个MM送的花都要针 对她个人的特点,每张卡片也要根据个人的特点来挑,我一个人哪搞得清楚,还是找花店老板和礼品店老板做一下Visitor, ...
- 自问自答之VR遐想
先让我组织一下语言,作为表达能力超弱的战五渣来讲,归纳总结什么的最要命了. 我可以给你分析个1到N条出来,但是一般来讲没什么顺序,想到什么就说什么.而且我属于线性思维,有一个引子就可以按着话头一步步发 ...