
分治
文章平均质量分 79
围巾的ACM
啊啊什么时候也能成为一个大牛啊
展开
-
poj 1741 Tree(树的分治)
思路:转自别人的: 将无根树转化成有根树进行观察。满足条件的点对有两种情况:两个点的路径横跨树根,两个点位于同一颗子树中。 如果我们已经知道了此时所有点到根的距离a[i],a[x] + a[y] 在进行分治时,为了避免树退化成一条链而导致时间复杂度变为O(N^2),每次都找树的重心,这样,所有的子树规模就会变的很小了。时间复杂度O(Nlog^2N)。 树的重心的算法可以线原创 2016-08-01 19:53:49 · 453 阅读 · 0 评论 -
51nod 1257 背包问题 V3(二分)
思路:二分答案然后判一判就可以了 #include using namespace std; const int maxn = 50000+7; #define LL long long LL gcd(LL a,LL b){return b==0?a:gcd(b,a%b);} int n,k; struct Node { int w,p; double rate; }beg[maxn原创 2016-09-21 01:01:05 · 974 阅读 · 0 评论 -
Educational Codeforces Round 15 C Cellular Network(二分)
题意:有n个城市m盏灯,要你确定一个最小的R使得所有的城市都被照亮 思路:二分答案R,然后直接扫一遍check就可以了 #include using namespace std; #define LL long long const int maxn = 1e5+7; LL a[maxn],b[maxn]; mapvis; int n,m; bool check(LL mid) {原创 2016-12-02 16:57:15 · 376 阅读 · 0 评论 -
Codeforces Round #409 C Voltage Keepsake(二分)
题意:有n个仪器,每个仪器每秒有a[i]消耗,自身有b[i]的存储,你有一个充电器,可以每秒充P的电,当某个仪器电量为0的时候就全部停止,问最大运行时间 思路:显然的二分一下答案嘛,然后check一下就可以了 #include using namespace std; #define LL long long const int maxn = 1e5+7; int n,p,a[maxn原创 2017-04-17 10:36:19 · 533 阅读 · 0 评论