[AT2384] [agc015_f] Kenus the Ancient Greek
题目链接
AtCoder:https://agc015.contest.atcoder.jp/tasks/agc015_f
洛谷:https://www.luogu.org/problemnew/show/AT2384
Solution
神仙结论题...窝只会打表找规律...
我们定义\(f(i,j)\)表示\((i,j)\)的\(\rm Euclidean\ step\ count\),也就是走多少步那个玩意。
定义\(Fib(n)\)表示斐波那契数列第\(n\)项,其中\(Fib(0)=Fib(1)=1\)。
有一个比较显然(好找出规律)的结论:\(f(Fib(x),Fib(x+1))=x\),且不存在任意\((i,j)\)满足\(f(i,j)\geqslant x,i< Fib(x),j< Fib(x+1)\),这个由(打表)数学归纳可得。
我们定义一个二元组\((x,y)\)是好的,当且仅当不存在\((i,j)\)满足\(i<x,j<y,f(i,j)>f(x,y)\),显然只有好的二元组能贡献答案。
我们定义一个二元组\((x,y)\)是优秀的,当且仅当\(x,y\leqslant Fib(v+2)+Fib(v-1)\),其中\(v=f(x,y)\)。
那么有一个结论:一个好的二元组进行一次\(\rm Euclidean\ step\)之后一定为一个优秀的二元组,证明如下:
我们考虑反证法证明,设好的二元组为\((a,b)=(y,py+x)\)满足\(x\leqslant y,f(x,y)=v+1\),优秀的二元组为\((x,y)\),假设\(y> Fib(v+2)+Fib(v-1)\):
可得:\(a=y>Fib(v+2),b=py+x\geqslant x+y>Fib(v)+F(v+2)+Fib(v-1)=Fib(v+3)\)。
注意到\(f(Fib(v+2),Fib(v+3))=v+2>f(a,b)\),即存在\((a',b')\)满足\(a'>a,b'>b\)且\(f(a',b')>f(a,b)\),与\((a,b)\)是好的二元组矛盾。
打表可知优秀的二元组并不多,貌似是\(O(\log^2 n)\)级别?我也不是特别清楚,所以我们可以把所有的优秀的二元组预处理出来,然后求答案就好了。
复杂度可能是\(O(q\log n)\)...
#include<bits/stdc++.h>
using namespace std;
#define int long long
void read(int &x) {
x=0;int f=1;char ch=getchar();
for(;!isdigit(ch);ch=getchar()) if(ch=='-') f=-f;
for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';x*=f;
}
void print(int x) {
if(x<0) putchar('-'),x=-x;
if(!x) return ;print(x/10),putchar(x%10+48);
}
void write(int x) {if(!x) putchar('0');else print(x);putchar('\n');}
#define lf double
#define ll long long
const int maxn = 110;
const int inf = 1e9;
const lf eps = 1e-8;
const int mod = 1e9+7;
#define pii pair<int,int >
#define fr first
#define sc second
#define vec vector<pii >
#define mp make_pair
#define pb push_back
#define iter vector <pii > :: iterator
vec t[maxn];
int n,m,q,f[maxn];
signed main() {
t[1].pb(mp(1,2)),t[1].pb(mp(1,3)),t[1].pb(mp(1,4));
f[0]=f[1]=1;for(int i=2;i<=100;i++) f[i]=f[i-1]+f[i-2];
for(int i=1;i<=100;i++)
for(int j=0,l=t[i].size()-1;j<=l;j++) {
int x=t[i][j].sc,y=t[i][j].fr+x;
while(y<=f[i+3]+f[i]) t[i+1].pb(mp(x,y)),y+=x;
}read(q);
for(int i=1;i<=q;i++) {
read(n),read(m);if(n>m) swap(n,m);
int p=1,ans=0;
while(f[p+1]<=n&&f[p+2]<=m) p++;
printf("%lld ",p);
if(p==1) {write(n%mod*m%mod);continue;}
for(int j=0,l=t[p-1].size()-1;j<=l;j++) {
int x=t[p-1][j].fr,y=t[p-1][j].sc;
if(y<=n) ans=(ans+(m-x)/y)%mod;
if(y<=m) ans=(ans+(n-x)/y)%mod;
}write(ans);
}
return 0;
}
[AT2384] [agc015_f] Kenus the Ancient Greek的更多相关文章
- agc015F - Kenus the Ancient Greek(结论题)
题意 题目链接 $Q$组询问,每次给出$[x, y]$,定义$f(x, y)$为计算$(x, y)$的最大公约数需要的步数,设$i \leqslant x, j \leqslant y$,求$max( ...
- agc015F Kenus the Ancient Greek
题意: 有$Q$次询问,每次给定$X_i$和$Y_i$,求对于$1\leq x \leq X_i , 1 \leq y \leq Y_i$,$(x,y)$进行辗转相除法的步数的最大值以及取到最大值的方 ...
- Atcoder Grand Contest 015 F - Kenus the Ancient Greek(找性质+乱搞)
洛谷题面传送门 & Atcoder 题面传送门 一道难度 Au 的 AGC F,虽然看过题解之后感觉并不复杂,但放在现场确实挺有挑战性的. 首先第一问很简单,只要每次尽量让"辗转相除 ...
- Atcoder训练计划
争取三天做完一套吧,太简单的就写一句话题解吧(其实也没多少会做的). 自己做出来的在前面用*标记 agc007 *A - Shik and Stone 暴力dfs即可,直接判断个数 *B - Cons ...
- A&G¥C015
A&G¥C015 A A+...+B Problem 正常A+B我还是会的,但是又加了个省略号就不会了/kk B Evilator 不会 C Nuske vs Phantom Thnook 以 ...
- POJ1151Atlantis 矩形面积并[线段树 离散化 扫描线]
Atlantis Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 21734 Accepted: 8179 Descrip ...
- 20151207Study
Liberal lawmakers proposed a bill to reduce the cost of medicine for older Americans.自由主义立法者提出一条减少老年 ...
- hdu 1542 & & poj 1151
Atlantis Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total S ...
- [POJ1151]Atlantis
[POJ1151]Atlantis 试题描述 There are several ancient Greek texts that contain descriptions of the fabled ...
随机推荐
- QTP日常积累
1.init同步测试对象 同步测试对象: CODE: Browser("百度一下,你就知道").Page("百度一下,你就知道").WebEdit(" ...
- 腾讯hr面
腾讯hr面面经 20181018 寒暄几句 hr自我介绍 hr介绍面试和最后出结果的时间周期 进入主题 自我介绍 考研成绩专业第一 聊考研(考研的经过.考研和保研) 本科成绩 考研成绩超长发挥还是正常 ...
- ats编译中增加透明度 选项
在大多数情况下,如果环境支持透明度,则configure将自动启用它.对于其他环境,可能需要 配置configure 选项. --enable-posix-cap 这实现了POSIX功能,这是透明度所 ...
- Hyperledger Fabric Ledger——账本总账
Ledger Ledger(账本)即所有的state transitions(状态切换),是有序且不可篡改的.state transitions(状态切换)是由参与方提交的chaincode(智能合约 ...
- SQL-Server collation, what is it and how to change db/column collation
The thing about collations is that although database have it's own collation, every table, and every ...
- Python入门学习系列——Python文件和异常
从文件中读取数据 首先准备一个文本文件,文件中存储着普通文本数据.读取文件需要调用open()和read()函数. 读取整个文件 代码示例: with open('pi_digits.txt') as ...
- 2017年软件工程作业-“Hello World!”团队互评beta版本
A.欢迎来怼——博客园安卓APP(测评人:刘淑霞) 博客地址:http://www.cnblogs.com/liusx0303/p/7905928.html B.Thunder——爱阅app(测评人: ...
- 第十周psp作业
本周psp 本周进度条 代码累积折线图 博文字数累积折线图 饼状图
- 利用JAVA制作简单登录窗口
import java.awt.Container; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; ...
- Struts2框架学习
Struts功能详解——ActionMapping对象 ActionMapping描述了struts中用户请求路径和Action的映射关系,在struts中每个ActionMapping都是通过pat ...