poj 2114 树的分治 可作模板】的更多相关文章

/* 啊啊啊啊啊啊啊本题证明一个问题,在实际应用中sort比qsort块 还有memset这类初始化能不加尽量别加,很浪费时间 原来的程序把qsort该成sort,去掉一个无用memset就a了时间不到一半 题意:和poj1741差不多,不过本题求的是dis[i]+dis[j]==dis[k]; */ #include<stdio.h> #include<string.h> #include<stdlib.h> #include<algorithm> usi…
思路:这题我是看 漆子超<分治算法在树的路径问题中的应用>写的. 附代码: #include<iostream> #include<cstring> #include<algorithm> #include<cstdio> #include<cmath> #define Maxn 10010 #define Maxm 20010 #define inf 0x7fffffff using namespace std; int head[…
Boatherds Time Limit: 2000MS Memory Limit: 65536K 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…
题目:https://vjudge.net/contest/307753#problem/B 题意:求树中路径和=k的点对是否存在 思路:点分治,这个题其实和上一题洛谷一样,只是这个数据强,我们不能直接预处理所有可能的路径长度,预处理所有路径长度复杂度 O(n^2) ,我们改为直接每次查询都分治一遍,我们只要把solve在O(n)求出来,那时间复杂度就是 O(n*logn*logn),时间上快了很多,其实等于k这个可以使用我们之前的方法.直接把不大于k的路径-小于k的路径=等于k的路径,然后搞一…
思路:1741的A1送 1. #include<iostream> #include<cstring> #include<algorithm> #include<cstdio> #include<cmath> #define Maxn 40010 #define Maxm 80010 #define inf 0x7fffffff using namespace std; int head[Maxn],vi[Maxn],e,ans,num,k,n,…
Tree Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 18205   Accepted: 5951 Description Give a tree with n vertices,each edge has a length(positive integer less than 1001). Define dist(u,v)=The min distance between node u and v. Give an…
原题链接:http://poj.org/problem?id=1741 题意: 给你棵树,询问有多少点对,使得这条路径上的权值和小于K 题解: 就..大约就是树的分治 代码: #include<iostream> #include<climits> #include<cstring> #include<queue> #include<algorithm> #include<vector> #include<cstdio>…
POJ-1741 题意: 对于带权的一棵树,求树中距离不超过k的点的对数. 思路: 点分治的裸题. 将这棵树分成很多小的树,分治求解. #include <algorithm> #include <iterator> #include <iostream> #include <cstring> #include <cstdlib> #include <iomanip> #include <bitset> #include…
题目链接: http://poj.org/problem?id=3468 题意: 输入 n, m表初始有 n 个数, 接下来 m 行输入, Q x y 表示询问区间 [x, y]的和: C x y z 表示区间 [x, y] 内所有数加上 z : 思路: 线段树区间更新&区间求和模板: 代码: #include <iostream> #include <stdio.h> #define ll long long #define lson l, mid, rt <<…
Description Give a tree with n vertices,each edge has a length(positive integer less than 1001). Define dist(u,v)=The min distance between node u and v. Give an integer k,for every pair (u,v) of vertices is called valid if and only if dist(u,v) not e…