摘要:
原题链接 根据题意我们可以得到一个很有趣的结论:处于同一行或者同一列的石头是共处一个集合的,而一个集合最终可以消除到只剩一个石头。(可以实验一下) 因此我们采取并查集实现。 Code class Solution { public: int sum=0; int father[1005]; map< 阅读全文
摘要:
原题链接 并查集模板练手。 递归版本 #include<bits/stdc++.h> using namespace std; const int N=1e4+5; int father[N]; int find(int mid){ if (father[mid]!=mid){ father[mid 阅读全文
摘要:
原题链接 解法一:二分搜素 首先我们知晓A-B=C,那么A=B+C,我们只需要遍历数组中的每一个元素然后在数组中搜素a[i]+c的值是否存在即可。 Code #include<bits/stdc++.h> using namespace std; typedef long long ll; cons 阅读全文