2025年4月5日
摘要:
拓扑排序,是对有向无环图(Directed Acylic Graph , DAG )进行的一种操作,这种操作是将DAG中的所有顶点排成一个线性序列,使得图中的任意一对顶点u,v满足如下条件: 若边(u,v)∈E(G),则在最终的线性序列中出现在v的前面 好了,说人话:拓扑排序的应用常常和AOV网相联
阅读全文
posted @ 2025-04-05 20:36
下头小美
阅读(74)
推荐(0)
2025年3月28日
摘要:
二 贪心 O nlogn; 解题思路 利用贪心 + 二分查找的思想。维护一个数组 q,其中 q[i] 表示长度为 i + 1 的最长上升子序列的末尾元素的最小值。 遍历数列:对输入数列中的每个元素 a[i] 进行处理。 二分查找:在 q 数组中通过二分查找找到第一个大于等于 a[i] 的位置。如果找
阅读全文
posted @ 2025-03-28 14:09
下头小美
阅读(58)
推荐(0)
2025年3月27日
摘要:
多源 BFS 算法问题:是有多个起始节点(源点),目标是找到从这些多个源点到图中其他各个可达节点的最短路径。例如在一个城市地图中,有多个垃圾回收站(源点),要计算各个小区到最近垃圾回收站的距离,就可能用到多源 BFS。多源 BFS 的核心在于初始化队列时将所有源点都放入队列,之后和单源 BFS 类似
阅读全文
posted @ 2025-03-27 20:38
下头小美
阅读(66)
推荐(0)
摘要:
我们关注的是'A'和'B'的数量差: diff[i] = countA[i] - countB[i]。 如果diff[i] == diff[j],这意味着从j+1到i的子串中'A'和'B'的数量相等(因为差值抵消了)。 include <bits/stdc++.h> using namespace
阅读全文
posted @ 2025-03-27 20:00
下头小美
阅读(38)
推荐(0)
2025年3月26日
摘要:
x is the root:x是根结点; x and y are siblings:x和y是兄弟结点; x is the parent of y:x是y的父结点; x is a child of y:x是y的一个子结点。 getline(cin,s); s.find("parents")!=stri
阅读全文
posted @ 2025-03-26 14:15
下头小美
阅读(32)
推荐(0)
2025年3月25日
摘要:
kruskal:时间复杂度是 O(mlogm) 𝑛 表示点数,𝑚表示边数 include<bits/stdc++.h> //#define int long long using namespace std; const int N=200010,inf=0x3f3f3f3f,mod=10007
阅读全文
posted @ 2025-03-25 17:34
下头小美
阅读(35)
推荐(0)
2025年3月23日
摘要:
toupperr tolower insert(s.begin()+i,'a')如果前面是s.begin()+i, 那么只能插入字符 insert(pos,"string") 在指定位置pos插入字符串 string s="123456 erase(s.begin()+1) 删除某一个 erase(
阅读全文
posted @ 2025-03-23 09:17
下头小美
阅读(40)
推荐(0)
2025年3月20日
posted @ 2025-03-20 15:12
下头小美
阅读(18)
推荐(0)
2025年3月19日
摘要:
include<bits/stdc++.h> using namespace std; struct node { node* lt; node* rt; int data; int id; }; // 插入节点 node* Insert(node* root, int data) { if (ro
阅读全文
posted @ 2025-03-19 21:30
下头小美
阅读(28)
推荐(0)
摘要:
include<bits/stdc++.h> using namespace std; const int N=10001; int tre[N]; void up(int x) { if(x==1) return ; else { if(tre[x/2]>tre[x]) swap(tre[x/2]
阅读全文
posted @ 2025-03-19 20:10
下头小美
阅读(25)
推荐(0)