• msc和mas(Wannafly挑战赛28)


    链接:https://ac.nowcoder.com/acm/contest/217/A
    来源:牛客网
     

    题目描述

    msc有一天遇见了mas,于是他们开始玩游戏。
    msc和mas初始各有一个正整数A和B,并且他们共同设置了一个阈值L。
    然后游戏就开始了,对于每一局操作的人,假设他手上拿着的是数字x,对手手上拿着的是数字y(记这一局开始时y的数值为y0),那么:
    1、如果x>L,那么他就胜利了,否则进入步骤2
    2、他会给对手的数值加上x(即),如果此时对手手上的数值y大于等于2y0,那么这一轮结束轮到对手操作,否则继续执行步骤2
    由于mas爱慕着msc,所以mas想知道当msc先手或后手时能否胜利。

    输入描述:

    一行三个正整数A,B和L,分别表示msc初始的数字,mas初始的数字和阈值。

    输出描述:

    一行两个字符串'Yes'或'No',分别表示msc先手以及后手时能否胜利,如果可以则输出'Yes',否则输出'No'(不包含单引号)。

    示例1

    输入

    复制

    232 42 9483

    输出

    复制

    No No

    备注:

    1≤ A,B,L≤ 109

    看似博弈题,但是模拟也能过,不知道是数据水,还是。。。

    AC代码:

    #include <iostream>
    
    using namespace std;
    typedef long long ll;
    int main(){
        int A,B,L;
        cin>>A>>B>>L;
        int x=A;
        int y=B;
        while(x<=L&&y<=L){ // A先手
            if(y<2*B){
                while(y<2*B)
                    y+=x;
            }
            else
                y+=x;
            if(y>L) break;
    
            if(x<2*A){
                while(x<2*A)
                    x+=y;
            }
            else
                x+=y;
            if(x>L) break;
        }
        if(x>L)cout<<"Yes ";
        else cout<<"No ";
    
    
        x=A;
        y=B;
        while(x<=L&&y<=L){ // A后手
            if(x<2*A){
                while(x<2*A)
                    x+=y;
            }
            else
                x+=y;
            if(x>L) break;
    
            if(y<2*B){
                while(y<2*B)
                    y+=x;
            }
            else
                y+=x;
            if(y>L) break;
        }
        if(x>L)cout<<"Yes ";
        else cout<<"No ";
        return 0;
    }

    另外 附上真*AC代码(偷来的代码,嘤嘤嘤)

    #include <iostream>
    #include <stdio.h>
    #include <math.h>
    #include <string.h>
    #include <time.h>
    #include <stdlib.h>
    #include <string>
    #include <bitset>
    #include <vector>
    #include <set>
    #include <map>
    #include <queue>
    #include <algorithm>
    #include <sstream>
    #include <stack>
    #include <iomanip>
    using namespace std;
    #define pb push_back
    #define mp make_pair
    typedef pair<int,int> pii;
    typedef long long ll;
    typedef double ld;
    typedef vector<int> vi;
    #define fi first
    #define se second
    #define fe first
    #define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
    #define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
    #define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
    #define es(x,e) (int e=fst[x];e;e=nxt[e])
    #define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
    ll l;
    string work(ll a,ll b,int c)
    {
        string p[2];
        p[0]="Yes"; p[1]="No";
        while(1)
        {
            if(a>l) return p[c];
            ll t=b*2; b+=b/a*a;
            while(b<t) b+=a;
            swap(p[0],p[1]);
            swap(a,b);
        }
    }
    int main()
    {
        ll a,b;
        cin>>a>>b>>l;
        cout<<work(a,b,0)<<" "<<work(b,a,1)<<"
    ";
    }
  • 相关阅读:
    公布一个IOS上线程安全的sqlite库 (转)
    iOS关于sqlite3操作(转)
    Navigation Bar的简单设置(转)
    NSUserDefaults standardUserDefaults的使用
    在XCode工程中创建bundle文件(转)
    Windows 8 游戏开发的那点儿事儿
    社交游戏进展报告
    用OpenXLive来开发windows phone 7社交游戏
    MongoDB的真正性能实战百万用户一一亿的道具
    MongoDB的真正性能
  • 原文地址:https://www.cnblogs.com/UUUUh/p/10284069.html
Copyright © 2020-2023  润新知