2025年3月28日
摘要:
二 贪心 O nlogn; 解题思路 利用贪心 + 二分查找的思想。维护一个数组 q,其中 q[i] 表示长度为 i + 1 的最长上升子序列的末尾元素的最小值。 遍历数列:对输入数列中的每个元素 a[i] 进行处理。 二分查找:在 q 数组中通过二分查找找到第一个大于等于 a[i] 的位置。如果找
阅读全文
posted @ 2025-03-28 14:09
下头小美
阅读(44)
推荐(0)
2025年3月27日
摘要:
多源 BFS 算法问题:是有多个起始节点(源点),目标是找到从这些多个源点到图中其他各个可达节点的最短路径。例如在一个城市地图中,有多个垃圾回收站(源点),要计算各个小区到最近垃圾回收站的距离,就可能用到多源 BFS。多源 BFS 的核心在于初始化队列时将所有源点都放入队列,之后和单源 BFS 类似
阅读全文
posted @ 2025-03-27 20:38
下头小美
阅读(51)
推荐(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
下头小美
阅读(20)
推荐(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
下头小美
阅读(21)
推荐(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
下头小美
阅读(12)
推荐(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
下头小美
阅读(29)
推荐(0)
2025年3月20日
摘要:
1 uh-oh@163.com 96 2 jack@ucla.edu 88 3 anyone@qq.com 87 3 cy@pat-edu.com 87 5 bob@cmu.edu 80 5 zoe@mit.edu 80 输出前5名 for(int i=1,j=i;i<=k;i=j) { while
阅读全文
posted @ 2025-03-20 15:12
下头小美
阅读(10)
推荐(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
下头小美
阅读(11)
推荐(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
下头小美
阅读(18)
推荐(0)
2025年3月18日
摘要:
stoi(string) string-》int tostring(int) int -> string
阅读全文
posted @ 2025-03-18 20:44
下头小美
阅读(7)
推荐(0)