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)<<"
";
}
原文地址:https://www.cnblogs.com/UUUUh/p/10284069.html