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:
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.
样例输入复制
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;
}
The Preliminary Contest for ICPC Asia Xuzhou 2019 徐州网络赛 A Who is better?的更多相关文章
- The Preliminary Contest for ICPC Asia Xuzhou 2019 徐州网络赛 K题 center
You are given a point set with nn points on the 2D-plane, your task is to find the smallest number o ...
- The Preliminary Contest for ICPC Asia Xuzhou 2019 徐州网络赛 XKC's basketball team
XKC , the captain of the basketball team , is directing a train of nn team members. He makes all mem ...
- The Preliminary Contest for ICPC Asia Xuzhou 2019 徐州网络赛 D Carneginon
Carneginon was a chic bard. But when he was young, he was frivolous and had joined many gangs. Recen ...
- The Preliminary Contest for ICPC Asia Xuzhou 2019 徐州网络赛 C Buy Watermelon
The hot summer came so quickly that Xiaoming and Xiaohong decided to buy a big and sweet watermelon. ...
- The Preliminary Contest for ICPC Asia Xuzhou 2019 徐州网络赛 B so easy
题目链接:https://nanti.jisuanke.com/t/41384 这题暴力能过,我用的是并查集的思想,这个题的数据是为暴力设置的,所以暴力挺快的,但是当他转移的点多了之后,我觉得还是我这 ...
- 计蒜客 41391.query-二维偏序+树状数组(预处理出来满足情况的gcd) (The Preliminary Contest for ICPC Asia Xuzhou 2019 I.) 2019年徐州网络赛)
query Given a permutation pp of length nn, you are asked to answer mm queries, each query can be rep ...
- The Preliminary Contest for ICPC Asia Xuzhou 2019 E XKC's basketball team [单调栈上二分]
也许更好的阅读体验 \(\mathcal{Description}\) 给n个数,与一个数m,求\(a_i\)右边最后一个至少比\(a_i\)大\(m\)的数与这个数之间有多少个数 \(2\leq n ...
- The Preliminary Contest for ICPC Asia Xuzhou 2019
A:Who is better? 题目链接:https://nanti.jisuanke.com/t/41383 题意: 类似于有N个石子,先手第一次不能拿完,每次后手只能拿 1 到 前一次拿的数量* ...
- The Preliminary Contest for ICPC Asia Xuzhou 2019 E. XKC's basketball team
题目链接:https://nanti.jisuanke.com/t/41387 思路:我们需要从后往前维护一个递增的序列. 因为:我们要的是wi + m <= wj,j要取最大,即离i最远的那个 ...
随机推荐
- 课程登记窗口java
设计窗口,实现课程的登记,并且将相应的数据写入文件之中.保证的是课程名称不可以重复,对于任课老师必须是在已经设定好的五位老师之中.并且上课地点也是在预先设定的范围内.窗口可以持续进行保存,数据将在判断 ...
- python 函数--迭代器
一.迭代协议: 可以被迭代要满足要求的就叫做可迭代协议.内部实现__iter__方法. iterable:可迭代的--对应的标志. 什么叫做迭代?:可以一个一个取值,就像for循环一样取值. 字符串, ...
- Linux网络安全篇,认识防火墙(一)
一.概念 防火墙分为软件防火墙和硬件防火墙.我们的主要讨论范围为软件防火墙. 软件防火墙又分为网络型和单一型的管理. 1.单一主机型防火墙 (1)数据包过滤型的Netfilter (2)依据服务软件程 ...
- Flask 入门(八)
flask操作数据库:操作数据: 承接上文: 修改main.py中的代码如下: #encoding:utf-8 from flask_sqlalchemy import SQLAlchemy from ...
- golang开发:环境篇(七) Go mod 使用
Glide用的好好的,为什么要使用Modules 在 Go 1.11 中 ,官方加入package management tool,称为Go Modules.Go mod 没有出现之前,用的最多的包管 ...
- Array(数组)对象-->数组的删除
1.数组的删除: 用delete操作符删除特定的元素 删除元素的位置只是被留空了,为undefined值 举例:删除下面数组中的第二个元素 var arr = [1,2,3,4,5]; /*删除第二个 ...
- 【python实现卷积神经网络】全连接层实现
代码来源:https://github.com/eriklindernoren/ML-From-Scratch 卷积神经网络中卷积层Conv2D(带stride.padding)的具体实现:https ...
- java 第七周课后作业0417
定义一个矩形类Rectangle:(知识点:对象的创建和使用)1 定义三个方法:getArea()求面积.getPer()求周长,showAll()分别在控制台输出长.宽.面积.周长.2 有2个属性: ...
- 深度解密 Go 语言之 sync.Pool
最近在工作中碰到了 GC 的问题:项目中大量重复地创建许多对象,造成 GC 的工作量巨大,CPU 频繁掉底.准备使用 sync.Pool 来缓存对象,减轻 GC 的消耗.为了用起来更顺畅,我特地研究了 ...
- Application.Exit
Application.Exit:通知winform消息循环退出.Environment.Exit:终止当前进程,返回exitcode给操作系统 Application.Exit会在所有前台线程退出后 ...