zoukankan      html  css  js  c++  java
  • The Preliminary Contest for ICPC Asia Xuzhou 2019 徐州网络赛 A Who is better?

    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:

    kle 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.

    样例输入复制

    2
    5 3
    3 2

    样例输出复制

    Lbnb!

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

    #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;
    }
  • 相关阅读:
    短url生成类
    websphere6.1部署SystemErr.log必须为元素类型“webapp”声明属性“ve
    解决websphere6.1必须为元素类型webapp声明属性version
    websphere6.1部署SystemErr.log必须为元素类型“webapp”声明属性“ve
    websphere6.1部署ear程序教程
    目测websphere6.1不支持dbcp1.4以及1.4以上版本
    maven与log4j之间的配置,log4j如何配置到web项目根目录下最简单方案
    在myeclipse中制作能部署到websphere上的java web程序教程制作ear
    【技术贴】servlet传参|前台传参含中文符号等 tomcat乱码 java后台接收乱码终极解决方
    【技术贴】servlet传参|前台传参含中文符号等 tomcat乱码 java后台接收乱码终极解决方
  • 原文地址:https://www.cnblogs.com/lunatic-talent/p/12798752.html
Copyright © 2011-2022 走看看