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;
}
- CSS魔法堂:重拾Border之——图片作边框
- Mobile Web中URL设计问题
- 使用root用户连接Ubuntu16.04时,提示SSH连接被拒绝
- CSS魔法堂:Box-Shadow没那么简单啦:)
- java操作redis: 将string、list、map、自定义的对象保存到redis中
- 运行第一个Docker容器-Docker for Web Developers(1)
- 手动实现jQuery Tools里面tab功能
- Angular企业级开发(9)-前后端分离之后添加验证码
- 基于thrift的微服务框架
- Sublime Text 快速格式化
- HTML中拖放介绍
- 打造高效前端工作环境 - tmux
- 基于thrift的微服务框架
- thrift中的超时(timeout)坑
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- go 中的 defer 使用及其规则
- 数据结构算法操作试题(C++/Python/Go)——938 二叉搜索树的范围和
- Android Studio 代理配置了Gradle依旧连接超时
- Dart 中变量类型 var, Object, dynamic 区别
- C++ 中的static关键字使用场景
- Dart 中的生产模式和检查模式
- 使用mysqladmin工具统计mysql当前的T/QPS
- MixIn 理解
- Day14:链表中倒数第k个结点
- Flutter开发笔记——BottomNavigationBar设置未选择Item颜色
- 访问虚拟机局域网服务拒绝连接
- uninstalling vim-minimal 同时也卸载了 sudo 解决方法
- 大点干!早点散----------深入剖析缓存加速--squid(反向代理与ACL访问控制以及sarg日志)
- JVM的Xms和Xmx参数设置为相同值有什么好处?
- 【CVPR 2020】一种新的门控通道注意力转换单元