首页 技术 正文
技术 2022年11月14日
0 收藏 349 点赞 3,899 浏览 1003 个字

就是找规律,发现每个父亲和孩子的差值都是距儿子最大的fibonacc

也是可证的

f[i]表示当前月的兔子总数

f[i]=f[i-1]+f[i-2](f[i-2]是新生的,f[i-1]是旧有的)

然后又学了一下set的用法

 1 #include<iostream>
2 #include<cstdio>
3 #include<string>
4 #include<algorithm>
5 #include<cmath>
6 #include<vector>
7 #include<map>
8 #include<set>
9 #include<cstring>
10 #define MAXN 1000001
11 #define int long long
12 using namespace std;
13 int l[MAXN],r[MAXN];
14 set<int>v;
15 int f[MAXN];int m;
16 void set_work()
17 {
18 f[1]=1;f[2]=2;
19 v.insert(f[1]);v.insert(f[2]);
20 for(int i=3;i<=60;++i)
21 {
22 f[i]=f[i-1]+f[i-2];
23 v.insert(f[i]);
24 }
25 }
26 int find(int x)
27 {
28 set<int>::iterator it;
29 it=v.lower_bound(x);
30 it--;
31 return *it;
32 }
33 int LCA(int x,int y)
34 {
35 if(x==y)return x;
36 if(x>y)swap(x,y);
37 if(x+1==y)return 1ll;
38 set<int>ss;
39 ss.insert(x);
40 while(x!=1)
41 {
42 x-=find(x);
43 ss.insert(x);
44 }
45 while(y!=1)
46 {
47 y-=find(y);
48 if(ss.count(y)!=0)
49 {
50 return y;
51 }
52 }
53 return 1;
54 }
55 signed main()
56 {
57 scanf("%lld",&m);
58 for(int i=1;i<=m;++i)
59 {
60 scanf("%lld%lld",&l[i],&r[i]);
61 }
62 set_work();
63 for(int i=1;i<=m;++i)
64 {
65 printf("%lld\n",LCA(l[i],r[i]));
66 }
67 }
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,083
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,558
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,407
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,180
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,817
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,900