程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> Codeforces Round #268 (Div. 1)A(構造)

Codeforces Round #268 (Div. 1)A(構造)

編輯:C++入門知識

Codeforces Round #268 (Div. 1)A(構造)


A. 24 Game time limit per test 1 second memory limit per test 256 megabytes input standard input output 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?

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 test(s) input
1
output
NO
input
8
output
YES
8 * 7 = 56
6 * 5 = 30
3 - 4 = -1
1 - 2 = -1
30 - -1 = 31
56 - 31 = 25
25 + -1 = 24

題意:用1-n的數字經過n-1次運算得到24
思路:1. n<=3 一定不可以
2. n>=4一定可以,為什麼呢
首先注意n=4時,可以通過1*2*3*4=24構造
然後看剩下還有多少個數,如果為偶數個,則前後兩兩相減得1,
然後就讓這些1只做乘運算,最後24 * 1 = 24
如果為奇數怎能辦呢
不難發現,n=5時,可以通過4*5+3+2-1=24構造
那麼剩下的數的數量一定為偶數了,解法同上

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved