摘要: 自测时间为2021年春季考试前一天下午$5:00 \sim 8:00$。 7-1 The Closest Fibonacci Number (20 分) The Fibonacci sequence $F_n$ is defined by $F_{n+2} = F_{n+1} + F_n$ for 阅读全文
posted @ 2021-03-12 20:41 Dazzling! 阅读(457) 评论(0) 推荐(0) 编辑
摘要: 额,这不是和1143 Lowest Common Ancestor (30 分)一模一样吗。 const int N=10010; int fa[N]; unordered_map<int,int> pos; int pre[N],in[N]; bool vis[N]; int n,m; int b 阅读全文
posted @ 2021-03-12 12:10 Dazzling! 阅读(44) 评论(0) 推荐(0) 编辑
摘要: 好家伙,$unordered_map$一直有一两个点超时,换成数组就过了,看来$STL$实现的哈希表还是没数组快啊。 向上标记法。 const int N=10010; int fa[N]; unordered_map<int,int> pos; int pre[N],in[N]; bool vis 阅读全文
posted @ 2021-03-12 11:57 Dazzling! 阅读(31) 评论(0) 推荐(0) 编辑
摘要: 数据范围小,用的暴力搜索法。 同步前进法。 const int N=110; int fa[N]; int dep[N],width[N]; int maxh,maxw; int n; int LCA(int u,int v) { if(dep[u] < dep[v]) swap(u,v); whi 阅读全文
posted @ 2021-03-12 10:23 Dazzling! 阅读(37) 评论(0) 推荐(0) 编辑
摘要: 最近公共祖先(Lowest Common Ancestors, LCA),是指在有根树中,某两个结点u和v最近的公共祖先。 u和v的公共祖先是指一个结点既是u的祖先,又是v的祖先。 u和v最近的公共祖先是指离u和v最近的公共祖先。 如果v本身就是u的祖先则u和v最近的公共祖先就是v。 可以利用LCA 阅读全文
posted @ 2021-03-12 09:53 Dazzling! 阅读(419) 评论(0) 推荐(0) 编辑
摘要: 水~,基于层序遍历。 树高最坏情况下为$n$,即为一条链。 const int N=35; unordered_map<int,int> pos; unordered_map<int,PII> tree; unordered_map<int,int> dep; int in[N],post[N]; 阅读全文
posted @ 2021-03-12 09:29 Dazzling! 阅读(32) 评论(0) 推荐(0) 编辑