2024年10月28日
摘要:
分类讨论:两种情况,一是有节点有两个父节点,二是头尾相连 1 struct UnionFind { 2 vector <int> ancestor; 3 4 UnionFind(int n) { 5 ancestor.resize(n); 6 for (int i = 0; i < n; ++i)
阅读全文
posted @ 2024-10-28 14:23
greenofyu
阅读(22)
推荐(0)
2024年10月27日
摘要:
题目给定一个树添加一条边后的图,需要找出添加的边。思路为遍历所有边,用并查集维护集合,当一条边的两个端点已经在同一集合时,说明即为最后添加的边。 1 const int N=1010; 2 int p[N]; 3 class Solution { 4 public: 5 int find(int x
阅读全文
posted @ 2024-10-27 13:04
greenofyu
阅读(9)
推荐(0)
2024年10月26日
摘要:
1 class Solution { 2 public: 3 int maxTotalReward(vector<int>& rewardValues) { 4 int m = ranges::max(rewardValues); 5 unordered_set<int> s; 6 for (int
阅读全文
posted @ 2024-10-26 12:22
greenofyu
阅读(31)
推荐(0)
2024年10月25日
摘要:
f(i,j)表示从前i个中选,奖励为j是否有方案,有则为1。f(i,j) |= f(i-1,j),表示不选第i个。若是要选第i个,则需要j-rewardValues[i] < rewardValues[i],表示选第i个时手上的价值小于第i个的价值。 1 const int N = 2010; 2
阅读全文
posted @ 2024-10-25 22:49
greenofyu
阅读(22)
推荐(0)
2024年10月24日
摘要:
题意为给定一个数组,数组头两数比大小,大的放队首,小的放队尾,找到能够连续赢K次的数的编号。 思路:如果一轮比较完了,没有赢K次的,那答案就是数组最大值。利用双指针,模拟一轮比较,计算每个数的胜利次数,注意,若起点不是0的话,意味着他和之前的数比较是胜出的,所以初始为1,否则初始为0; 1 clas
阅读全文
posted @ 2024-10-24 14:05
greenofyu
阅读(31)
推荐(0)
2022年3月22日
摘要:
A:水题。 链接:https://www.acwing.com/problem/content/4379/ 1 #include <iostream> 2 #include <cstring> 3 #include <algorithm> 4 #include <map> 5 using names
阅读全文
posted @ 2022-03-22 20:06
greenofyu
阅读(46)
推荐(0)
2022年2月26日
摘要:
A:签到题,直接模拟即可 题目地址:https://www.acwing.com/problem/content/4308/ 1 #include <iostream> 2 #include <cstring> 3 #include <algorithm> 4 #include <set> 5 6
阅读全文
posted @ 2022-02-26 22:21
greenofyu
阅读(46)
推荐(0)
2021年8月20日
摘要:
A:水题,预处理一下符合题目要求的数即可。 1 #include <iostream> 2 #include <cstring> 3 #include <algorithm> 4 #include<queue> 5 #include<unordered_map> 6 using namespace
阅读全文
posted @ 2021-08-20 21:26
greenofyu
阅读(31)
推荐(0)
2021年7月6日
摘要:
A:模拟题。 1 class Solution { 2 public: 3 vector<int> buildArray(vector<int>& nums) { 4 int n=nums.size(); 5 vector<int> ans(n); 6 for(int i=0;i<n;i++){ 7
阅读全文
posted @ 2021-07-06 22:59
greenofyu
阅读(55)
推荐(0)
摘要:
A:水题。 https://www.acwing.com/problem/content/3736/ 1 #include <iostream> 2 #include <cstring> 3 #include <algorithm> 4 using namespace std; 5 const in
阅读全文
posted @ 2021-07-06 22:51
greenofyu
阅读(27)
推荐(0)