【POJ2114】Boatherds 树分而治之】的更多相关文章

做广告: #include <stdio.h> int main() { puts("转载请注明出处[vmurder]谢谢"); puts("网址:blog.csdn.net/vmurder/article/details/44308173"); } 题意: 求是否有长度为K的路径. 每组数据 N,表示树有N个点. 然后N行,每行若干个数对(a,b)(a,b),当中第i行时表示i到a有一条长为b的无向边.输入到0截止. 然后若干个数表示K,每一个数输出下…
Boatherds     Description Boatherds Inc. is a sailing company operating in the country of Trabantustan and offering boat trips on Trabantian rivers. All the rivers originate somewhere in the mountains and on their way down to the lowlands they gradua…
Description Boatherds Inc. is a sailing company operating in the country of Trabantustan and offering boat trips on Trabantian rivers. All the rivers originate somewhere in the mountains and on their way down to the lowlands they gradually join and f…
做广告: #include <stdio.h> int main() { puts("转载请注明出处[vmurder]谢谢"); puts("网址:blog.csdn.net/vmurder/article/details/44302921"); } 题意: 给你一棵无根树,求有多少点对之间距离<=K. 题解: 树分治. 然后对于一个重心X.我们把它的全部子树中的全部点存到结构体数组中. 结构体中存距离和子树编号. 第一遍sort,我们双指针扫哪些…
还是利用点的分治的办法来做,统计的办法不一样了,我的做法是排序并且标记每个点属于哪颗子树. #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int maxn=1e4+9; int head[maxn],lon,n,mm,m; struct { int next,to,w; }e[maxn<&l…
三道题都很类似.给出1741的代码 #include<cstdio> #include<algorithm> #include<cstring> using namespace std; #define MAXN 10001 typedef pair<int,int> Point; int n,K,ans; int v[MAXN<<1],w[MAXN<<1],first[MAXN],next[MAXN<<1],en; vo…
poj2114 Boatherds Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 1195   Accepted: 387 Description Boatherds Inc. is a sailing company operating in the country of Trabantustan and offering boat trips on Trabantian rivers. All the rivers…
http://poj.org/problem?id=2114 (题目链接) 题意 给出一棵树,问是否存在两点间的距离为K. Solution 点分治嘛,跟poj1741差不多.. 然而为什么我调了一个下午..map真是坑死了,各种TLE,以后再也不写了. 代码 // poj2114 #include<algorithm> #include<iostream> #include<cstdlib> #include<cstring> #include<cs…
标题效果:鉴于一棵树,问有两点之间没有距离是k的. 数据的多组 思维:和IOI2011的Race喜欢.不是这么简单.阅读恶心,我是在主要功能的别人的在线副本. CODE: #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #define MAX 10010 #define INF 0x3f3f3f3f using namespace std; int p…
poj1741板子套一套,统计对数的方式改一下,可以在O(n)时间内统计对数 最后不要忘记输出最后的“.” /* 给定一棵边权树,是否存在一条路径使得其长度为恰好为x 把1741的板子改为求点对之间的距离=k的点对数即可 */ #include<iostream> #include<cstring> #include<cstdio> #include<algorithm> #define MAXN 10010 using namespace std; int…