前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >The Preliminary Contest for ICPC Asia Xuzhou 2019 徐州网络赛 A Who is better?

The Preliminary Contest for ICPC Asia Xuzhou 2019 徐州网络赛 A Who is better?

作者头像
风骨散人Chiam
发布2020-10-28 10:16:07
2960
发布2020-10-28 10:16:07
举报
文章被收录于专栏:CSDN旧文

A

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 11 enemy and 22 times the number of enemies that the former has just destroyed (including 11 enemy and 22 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 kk sets of integers aa and bb such that nn ≡ bb (mod aa).
  • nn is the minimum positive integer solution satisfying the kk groups aa and bb.

Input

In the first line, input kk, and on lines 22 to k + 1k+1, input kk groups aa and bb.

Output

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

Note:

k\le 10k≤10 ,1< n \le 10^{15}n≤1015

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

样例输入复制

代码语言:javascript
复制
2
5 3
3 2

样例输出复制

代码语言:javascript
复制
Lbnb!

扩展式中国剩余定理+斐波那契博弈,先打表找规律,找到必输的情况。

代码语言:javascript
复制
#include<iostream>
#include<cstdio>
#include<cmath>
#include<map>
using namespace std;
#define LL long long
LL mi[1100],ai[1100],fb[1100];//mi为要模的数,ai为余数。
map<LL,bool>p;
LL gcd(LL a, LL b)
{
    return b == 0 ? a : gcd(b, a%b);
}
void exgcd(LL a, LL b, LL &d, LL &x, LL &y)
{
    if(!b)
    {
        d = a, x = 1, y = 0;
    }
    else
    {
        exgcd(b, a%b, d, y, x);
        y -= x * (a / b);
    }
}
LL CRT(LL l, LL r, LL *mi, LL *ai)
{
    LL lcm = 1;
    for(LL i = l; i <= r; i++)
        lcm = lcm / gcd(lcm, mi[i]) * mi[i];
    for(LL i = l+1; i <= r; i++)
    {
        LL A = mi[l], B = mi[i], d, x, y, c = ai[i] - ai[l];
        exgcd(A, B, d, x, y);
        if(c % d)
            return -1;
        LL mod = mi[i] / d;
        LL k = ((x * c / d) % mod + mod) % mod;
        ai[l] = mi[l] * k + ai[l];
        mi[l] = mi[l] * mi[i] / d;
    }
    if(ai[l] == 0)
        return lcm;
    return ai[l];
}
int main()
{
    LL t,n,i;
    scanf("%lld",&t);
    for(i=1; i<=t; i++)
        scanf("%lld%lld",&mi[i],&ai[i]);
    n=CRT(1ll,t,mi,ai);
    if(n>1e15||n==-1)
    {
        printf("Tankernb!");
        return 0;
    }
    fb[1]=2,fb[2]=3;
    p[2]=true,p[3]=true;
    for(i=3;i<=320;i++)
    {
        fb[i]=fb[i-1]+fb[i-2];
        if(fb[i]>1e15)
        break;
        p[fb[i]]=true;
    }
    if(p[n])
        printf("Lbnb!");
    else printf("Zgxnb!");
      return 0;
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019/09/07 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Input
  • Output
  • Note:
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档