HDU 5723 最小生成树上的期望】的更多相关文章

题意:求最小生成树,和任意两个点之间距离的期望 官方题解: 最后求两遍点的积的时候,还是要判断父子关系. 注意 long long #include <bits/stdc++.h> using namespace std; typedef long long LL; +; int father[maxn]; int Find_Set(int x) { if(x!=father[x]) father[x] = Find_Set(father[x]); return father[x]; } st…
Abandoned country 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5723 Description An abandoned country has n(n≤100000) villages which are numbered from 1 to n. Since abandoned for a long time, the roads need to be re-built. There are m(m≤1000000) ro…
题目链接:hdu 5723 Abandoned country 题目大意:N个点,M条边:先构成一棵最小生成树,然后这个最小生成树上求任意两点之间的路径长度和,并求期望 /************************************************************** Problem:hdu 5723 User: youmi Language: C++ Result: Accepted Time:2932MS Memory:22396K solution:首先注意到任…
Abandoned country Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 4477    Accepted Submission(s): 1124 Problem Description An abandoned country has n(n≤100000) villages which are numbered from 1…
HDU 5723 Abandoned country(落后渣国) Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Description 题目描述 An abandoned country has n(n≤100000) villages which are numbered from 1 to n. Since abandoned for a long time, the r…
Qin Shi Huang's National Road System Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 6137    Accepted Submission(s): 2143 Problem Description During the Warring States Period of ancient China(47…
HDU 1233(最小生成树 模板) #include <iostream> #include <algorithm> #include <cstdio> using namespace std; typedef struct { int a,b; int v; }node; const int maxn=105; int ans; int father[maxn]; node graph[maxn*(maxn-1)/2]; int Find(int x) { if(f…
任意门:http://acm.hdu.edu.cn/showproblem.php?pid=5723 Abandoned country Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 7573    Accepted Submission(s): 1850 Problem Description An abandoned country…
http://acm.hdu.edu.cn/showproblem.php?pid=5723 Abandoned country Problem Description   An abandoned country has n(n≤100000) villages which are numbered from 1 to n. Since abandoned for a long time, the roads need to be re-built. There are m(m≤1000000…
Abandoned country Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1756    Accepted Submission(s): 475 Problem Description An abandoned country has n(n≤100000) villages which are numbered from 1…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5723 n个村庄m条双向路,从中要选一些路重建使得村庄直接或间接相连且花费最少,这个问题就是很明显的求最小生成树,由于边权各不相同,所以最小生成树唯一. 然后,在这个最小生成树的基础上,求各个路径的最小期望和(推导出 期望 = 所有村庄中任意两个村庄距离之和 / 村庄对数). 最小生成树很好求(边权从小到大,并查集一下就好了). 然后求以上基础村庄中任意两个村庄距离之和,只要求每条边乘上每条边出现的次…
Abandoned country 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5723 Description An abandoned country has n(n≤100000) villages which are numbered from 1 to n. Since abandoned for a long time, the roads need to be re-built. There are m(m≤1000000) ro…
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5723 [题目大意] n座城市,m条路径,求解: 1.最短的路径和,使得n座城市之间直接或者间接连通 2.在路径和最短的情况下,求出任意两个城市之间的期望距离 [题解] 对于问题1,只需求出该图的最小生成树,边权和即答案,由于边权值唯一,因此不存在最小生成树多解的情况. 对于问题2,期望的通常求法为(任意两点之间的路径和)/(点对数) 那么问题就转化为任意两点间距离和的问题,我们按边考虑,对于每条…
http://acm.split.hdu.edu.cn/showproblem.php?pid=5723 题意:给出一个无向图,每条路都有一个代价,求出把所有城市连通的最小代价.在此基础上,国王会从这里面随机挑出两个城市作为起点和终点,求出国王要走的路的期望值. 思路: 第一问很简单,最小生成树计算一下即可. 对于第二问,在新图的基础上,考虑每条边所能给出的贡献值.假设这条边两个的点数分别为x和y,那么这条边总的贡献次数就是x*y,贡献值为x*y*w.求两边的点数dfs即可. #include<…
Abandoned country Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 3006    Accepted Submission(s): 346 Problem Description An abandoned country has n(n≤100000) villages which are numbered from 1…
1.HDU  1102  Constructing Roads    最小生成树 2.总结: 题意:修路,裸题 (1)kruskal //kruskal #include<iostream> #include<cstring> #include<cmath> #include<queue> #include<algorithm> #include<cstdio> #define max(a,b) a>b?a:b using na…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4405 题意:从0走到n,每次走之前掷一次筛子,掷出几点就向前走几点,走到大于等于n的地方就停止.但是,有些地方可以连着走,即到达这个地方时可以接着到达以后的某个格子.问停止是掷骰子的期望? 思路: E(i) (i>=n) 全部为0 对于0<i<n E(i)=(E(i+1)+E(i+2)+E(i+3)+E(i+4)+E(i+5)+E(i+6))/6+1 如果i会被传送到j 那么E(i)=E(j…
Problem Description   You live in a village but work in another village. You decided to follow the straight path between your house (A) and the working place (B), but there are several rivers you need to cross. Assume B is to the right of A, and all…
题目说每条边权值都不一样,说明最小生成树是唯一的,不存在最小期望这一说. 然后就是先求出最小生成树,随便确定一个根节点,计算出每个点的子树有多少节点,记为c[x]. 指向x的这条边被统计的次数为c[x]*(n-c[x]).然后基本就可以算出答案了. #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<vector> #include<…
题意是给定一长为 L 的木棒,每次任意切去一部分直到剩余部分的长度不超过 D,求切割次数的期望. 若木棒初始长度不超过 D,则期望是 0.000000: 设切割长度为 X 的木棒切割次数的期望是 F(X). 则 F(X) = F(切割点位置为 0 ~ D) + F(切割点位置为 D ~ X ) + 1:(此处的 +1 是指首次切割产生的次数) 而 F(切割点位置为 0 ~ D ) = 0:(因为已无需再切割) 令下一次切割点的位置为 T, F(切割点位置为 D ~ X ) = 在D~X上积分 (…
Problem DescriptionAn abandoned country has n(n≤100000) villages which are numbered from 1 to n. Since abandoned for a long time, the roads need to be re-built. There are m(m≤1000000) roads to be re-built, the length of each road is wi(wi≤1000000). G…
poj 1251  && hdu 1301 Sample Input 9 //n 结点数A 2 B 12 I 25B 3 C 10 H 40 I 8C 2 D 18 G 55D 1 E 44E 2 F 60 G 38F 0G 1 H 35H 1 I 353A 2 B 10 C 40B 1 C 200Sample Output 21630 prim算法 # include <iostream> # include <cstdio> # include <cstr…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4336 题意: 一共有n种卡片.每买一袋零食,有可能赠送一张卡片,也可能没有. 每一种卡片赠送的概率为p[i],问你将n种卡片收集全,要买零食袋数的期望. 题解: 表示状态: dp[state] = expectation state表示哪些卡片已经有了 找出答案: ans = dp[0] 什么都没有时的期望袋数 如何转移: 两种情况,要么得到了一张新的卡片,要么得到了一张已经有的卡片或者啥都没有.…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4405 题意: 你在下简化版飞行棋... 棋盘为一个线段,长度为n. 上面有m对传送门,可以直接将你从a[i]传送到b[i]处. 每扔一次骰子,可以向前移动的步数为骰子的点数. 你的初始位置为0.当位置>=n时,游戏结束. 问你扔骰子次数的期望. 题解: 表示状态: dp[i] = rest steps 位置为i时,剩余需要掷骰子次数的期望. 找出答案: ans = dp[0](初始位置) 如何转移:…
Let’s talking about something of eating a pocky. Here is a Decorer Pocky, with colorful decorative stripes in the coating, of length L. While the length of remaining pocky is longer than d, we perform the following procedure. We break the pocky at an…
最小生成树prime版 大致的步骤 首先选取一个到集合最近的点 然后标记起在集合内部 然后更新最短距离 畅通工程再续 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 24846    Accepted Submission(s): 8035 Problem Description 相信大家都听说一个“百岛湖”的地方吧,百岛湖的居民生活在不…
#include<iostream> #include<cstdio> #include<algorithm> #include<cmath> #include<cstring> #define MAX 0xffffffff //定义一个最小生成树中不可能达到的值 +; // 点的上限 using namespace std; struct point{ int x,y; }node[qq]; double lowcost[qq][qq]; //…
题意:沿着x轴从0走到大于等于N的某处,每一步的步数由骰子(1,2,3,4,5,6)决定,若恰好走到x轴上某飞行路线的起点,则不计入扔骰子数.问从0走到大于等于N的某处的期望的扔骰子次数. 分析: 1.dp[i]表示从位置i到终点期望的扔骰子次数. 2.很显然倒着往前推,因为从起点0开始,扔骰子的次数有很多种可能,难以计算,但是dp[N]很显然是0,不需要扔骰子即可到达终点. 3.假设当前位于位置i,根据骰子数可能到达的位置有i + j(j=1,2,3,4,5,6),到达其中每个位置的概率都是1…
题目大意: 就是根据它给的程序的要求,不断平移,缩放,旋转三维的点,最后计算出点的位置 这里主要是要列出三种转换方式的齐次矩阵描述 平移translate tx ty tz1 0 0 00 1 0 00 0 1 0tx ty tz 1缩放scale a b ca  0  0  00  b  0  00  0  c  00  0  0  1绕任意轴(过原点)旋转(注意要把轴向量归一化,否则点在旋转轴上时有问题) 这里是以(x,y,z)向量指向我们人的方向逆时针旋转 d 的弧度rotate x y…
赤裸裸最小生成树,没啥说的,我用kruskal过的 /* * Author : ben */ #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <ctime> #include <iostream> #include <algorithm> #include <queue> #include <…