zoukankan      html  css  js  c++  java
  • ZJNU 1702

    ZJNU 1702 - 24 Game

    题面

    一个“24点游戏”,但是他没有那么简单。他是一个新的游戏。

    你有(n)个整数:(1-n)。每一个操作,都可以将两个数合成一个数,你可以使用加减乘。

    问在(n-1)个步骤后,你能不能得出(24)


    思路

    比较有意思的一道小模拟,实际上模拟题做多了很容易就能往找规律的方向上想(结果今天才过掉这题QAQ)

    讨论(n)较小时的解:

    发现(n=1,2,3)时不存在答案;

    (n=4)时,(1 imes 2 imes 3 imes 4=24)

    (n=5)时,(4 imes 5+2+3-1=24)

    (6)开始,发现两两相邻的数相减(=1),然后(24 imes 1=24)​消除这两个数。偶数(n)可以接在(n=4)后面,奇数(n)可以接在(n=5)后面。


    #include<bits/stdc++.h>
    #define closeSync ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
    #define multiCase int T;cin>>T;for(int t=1;t<=T;t++)
    #define rep(i,a,b) for(int i=(a);i<=(b);i++)
    #define repp(i,a,b) for(int i=(a);i<(b);i++)
    #define per(i,a,b) for(int i=(a);i>=(b);i--)
    #define perr(i,a,b) for(int i=(a);i>(b);i--)
    #define all(a) (a).begin(),(a).end()
    #define SUM(a) accumulate(all(a),0LL)
    #define MIN(a) (*min_element(all(a)))
    #define MAX(a) (*max_element(all(a)))
    #define mst(a,b) memset(a,b,sizeof(a))
    #define pb push_back
    #define eb emplace_back
    #define fi first
    #define se second
    using namespace std;
    typedef long long ll;
    typedef unsigned long long ull;
    typedef pair<int,int> pii;
    const int INF=0x3f3f3f3f;
    const ll LINF=0x3f3f3f3f3f3f3f3f;
    const double eps=1e-12;
    const double PI=acos(-1.0);
    const ll mod=998244353;
    const int dx[8]={0,1,0,-1,1,1,-1,-1},dy[8]={1,0,-1,0,1,-1,1,-1};
    void debug(){cerr<<'
    ';}template<typename T,typename... Args>void debug(T x,Args... args){cerr<<"[ "<<x<< " ] , ";debug(args...);}
    mt19937 mt19937random(std::chrono::system_clock::now().time_since_epoch().count());
    ll getRandom(ll l,ll r){return uniform_int_distribution<ll>(l,r)(mt19937random);}
    ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
    ll qmul(ll a,ll b){ll r=0;while(b){if(b&1)r=(r+a)%mod;b>>=1;a=(a+a)%mod;}return r;}
    ll qpow(ll a,ll n){ll r=1;while(n){if(n&1)r=(r*a)%mod;n>>=1;a=(a*a)%mod;}return r;}
    ll qpow(ll a,ll n,ll p){ll r=1;while(n){if(n&1)r=(r*a)%p;n>>=1;a=(a*a)%p;}return r;}
    
    int n;
    
    void solve()
    {
        cin>>n;
        if(n<=3)
        {
            cout<<"NO
    ";
            return;
        }
        cout<<"YES
    ";
        if(n%2==0)
        {
            cout<<"1 * 2 = 2
    ";
            cout<<"2 * 3 = 6
    ";
            cout<<"6 * 4 = 24
    ";
            for(int i=6;i<=n;i+=2)
            {
                cout<<i<<" - "<<i-1<<" = 1
    ";
                cout<<"24 * 1 = 24
    ";
            }
        }
        else
        {
            cout<<"4 * 5 = 20
    ";
            cout<<"20 + 3 = 23
    ";
            cout<<"23 + 2 = 25
    ";
            cout<<"25 - 1 = 24
    ";
            for(int i=7;i<=n;i+=2)
            {
                cout<<i<<" - "<<i-1<<" = 1
    ";
                cout<<"24 * 1 = 24
    ";
            }
        }
    }
    int main()
    {
        closeSync;
        //multiCase
        {
            solve();
        }
        return 0;
    }
    

  • 相关阅读:
    python 复杂一点的装饰器
    python 装饰器
    python 歌词解析
    ATX 免越狱调试IOS和Android
    OpenCV库文件介绍
    NetEaseGame/ATX 的MD
    带你玩转Visual Studio——带你高效开发
    python 图像识别
    fatal: Authentication failed for又不弹出用户名和密码 解决办法
    lua luna工具库
  • 原文地址:https://www.cnblogs.com/stelayuri/p/15138417.html
Copyright © 2011-2022 走看看