Who is better?(2019 ACM-ICPC 徐州赛区网络赛 A)

Problem Description

After Asgard was destroyed, tanker brought his soldiers to earth, and at the same time took on the important task of protecting the peace of the earth. The best two solders were lb and zgx, were very capable, but they always disliked each other. However, one day they encountered a group of foreign invaders (many, but how many only tanker knew). They were all strong enough to destroy the enemy easily. But they found it too boring, so they agreed to follow some rules to deal with the invaders by taking turns, and if one of them had no enemies when it was his turn, he would later admit that the other man was better.

The rules are as follows:

  • zgx takes the first turn. But he cannot destroy all the enemies at the first time;
  • after that, the number of enemies that can be destroyed at a time is between 1 enemy and 2 times the number of enemies that the former has just destroyed (including 1 enemy and 2 times the number of enemies that the opponent has just destroyed).
  • the winner is the one who agrees to destroy the last enemy. Both zgx and lb are smart, so they only perform actions that are best for them.

To ensure fairness, they found their leader, tanker, to judge, but tanker just wanted people to say he was great, so he didn't want them to decide easily, so he hid the number of intruders in a question:

  • there are k sets of integers a and b such that n ≡ b (mod a).
  • nn is the minimum positive integer solution satisfying the kk groups a and b.

Input

In the first line, input k, and on lines 2 to k+1, input k groups a and b.

note

k≤10 ,n≤10^15

For the sample,n=8,because 8%5=3, 8%3=2 and 8 is the smallest possible integer that is fit the requirement.

Output

If lb wins, output "Lbnb!", if zgx wins, output "Zgxnb!", if they can't solve, (n does not exist) , output "Tankernb!" .

Sample Input

2
5 3
3 2

​​​​​​​Sample ​​​​​​​Output

Lbnb!

题意:给出 k 组同余方程的除数 a 余数 b,求出敌人总数 n 后,两个人轮流进行博弈,第一轮不能杀死所有人,第二轮的杀死人数在 1~2*上一轮杀死的人数 之间,第三轮依次类推,问最后谁胜

思路:首先是利用不互素的中国剩余定理模版求出敌人总数 n,然后又是一个斐波那契博弈的模版

Source Program

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LL long long
#define Pair pair<int,int>
LL quickPow(LL a,LL b){ LL res=1; while(b){if(b&1)res*=a; a*=a; b>>=1;} return res; }
LL quickModPow(LL a,LL b,LL mod){ LL res=1; a=a%mod; while(b){if(b&1)res=(a*res)%mod; a=(a*a)%mod; b>>=1;} return res; }
LL getInv(LL a,LL mod){ return quickModPow(a,mod-2,mod); }
LL GCD(LL x,LL y){ return !y?x:GCD(y,x%y); }
LL LCM(LL x,LL y){ return x/GCD(x,y)*y; }
const double EPS = 1E-10;
const int MOD = 1E9+7;
const int N = 100000+5;
const int dx[] = {-1,1,0,0,-1,-1,1,1};
const int dy[] = {0,0,-1,1,-1,1,-1,1};
using namespace std;


LL Extended_GCD(LL a,LL b,LL &x,LL &y) {
    if(b==0) {
        x=1;
        y=0;
        return a;
    }

    LL gcd=Extended_GCD(b,a%b,y,x);
    y=y-a/b*x;
    return gcd;
}
LL CRT(LL W[],LL B[],LL n) { //w为除数,b为余数,n为有多少式子
    LL res=B[0],Wi=W[0];
    for(LL i=1; i<n; i++) {
        LL bi=B[i],wi=W[i];
        LL x,y;
        LL gcd=Extended_GCD(Wi,wi,x,y);
        LL c=bi-res;

        if(c%gcd!=0)//表示没有结果
            return -1;

        LL M=wi/gcd;
        res+=Wi*( ((c/gcd*x)%M+M) % M);
        Wi*=M;
    }
    if(res==0) { //除数全为0
        res=1;
        for(LL i=0; i<n; i++)
            res=res*W[i]/GCD(res,(LL)W[i]);
    }
    return res;
}
LL a[N],b[N];
LL fib[200+5];
void fibonacci(int n){
    fib[1]=0LL;
    fib[2]=1LL;
    for(int i=3;i<=n;i++)
       fib[i]=fib[i-2]+fib[i-1];
}
int main(){
    fibonacci(93);

    int n;
    scanf("%d",&n);
    for(int i=0; i<n; ++i)
        scanf("%lld%lld",&a[i],&b[i]);//除数、余数
    LL res=CRT(a,b,n);

    if(res==-1)
        printf("Tankernb!\n");
    else{
        bool flag=false;
        for(int i=1;i<=93;i++){
            if(fib[i]==res){
                printf("Lbnb!\n");
                flag=true;
                break;
            }
        }
        if(!flag)
            printf("Zgxnb!\n");
    }
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值