上一页 1 ··· 27 28 29 30 31 32 33 34 35 ··· 67 下一页
摘要: 二分 问题显然具有二段性。 每一步过程中$E=2*E-h[i]$,$n$的范围为$10^5$,中间过程可能溢出。 观察到如果中间某步满足$E \ge maxh$,则之后过程$E$的值一定非负,可以抵达终点。 const int N=1e5+10; int h[N],maxh; int n; bool 阅读全文
posted @ 2021-03-17 18:15 Dazzling! 阅读(55) 评论(0) 推荐(0) 编辑
摘要: 签到题。 int n; int main() { cin>>n; int res=0; for(int i=0;i<n;i++) { int score,w; cin>>w>>score; res+=w*score; } cout<<max(res,0)<<endl; //system("pause 阅读全文
posted @ 2021-03-14 12:08 Dazzling! 阅读(65) 评论(0) 推荐(0) 编辑
摘要: 思路 枚举$1 \sim 9$的全排序 枚举分界处的位置 时间复杂度:\(O(9! \times 9 \times C_8^3)\) int path[10]; bool vis[10]; int n; int ans; void dfs(int u) { if(u == 9) { int a=0; 阅读全文
posted @ 2021-03-14 11:45 Dazzling! 阅读(74) 评论(0) 推荐(0) 编辑
摘要: 题意 给出两个序列作为二叉树的先序序列和后序序列,序列内数字各不相同,判断是否能唯一确定一棵二叉树。输出任意一棵符合的二叉树的中序序列。 思路 以上图为例进行说明,该图左的二叉树对应的先序序列和后序序列如该图右所示。 可以知道的一点是,先序序列的第一个结点和后序序列的最后一个结点都表示根结点,因此一 阅读全文
posted @ 2021-03-13 11:43 Dazzling! 阅读(47) 评论(0) 推荐(0) 编辑
摘要: 自测时间为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) 编辑
摘要: 水~,基于层序遍历。 树高最坏情况下为$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) 编辑
摘要: 和1147 Heaps (30 分)类似,$30$分水了。 const int N=1010; int heap[N]; bool minheap,maxheap; int n; void dfs(int u,vector<int> &path) { if(u*2 > n)//叶子结点 { for( 阅读全文
posted @ 2021-03-11 22:28 Dazzling! 阅读(32) 评论(0) 推荐(0) 编辑
上一页 1 ··· 27 28 29 30 31 32 33 34 35 ··· 67 下一页