/* 迭代法 :204Ms */ #include<stdio.h> #include<string.h> #include<math.h> #define N 1100 #define eps 1e-10 #define inf 0x3fffffff struct node { int u,v,w; }p[N]; double ma[N][N]; double distance(int i,int j) { return sqrt(1.0*(p[i].u-p[j].u…
题目描述: David the Great has just become the king of a desert country. To win the respect of his people, he decided to build channels all over his country to bring water to every village. Villages which are connected to his capital village will be water…
Language: Default Desert King Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 22113   Accepted: 6187 Description David the Great has just become the king of a desert country. To win the respect of his people, he decided to build channels…
思路:设sum(cost[i])/sum(dis[i])=r;那么要使r最小,也就是minsum(cost[i]-r*dis[i]);那么就以cost[i]-r*dis[i]为边权重新建边.当求和使得最小生成树的 sum(cost[i]-r*dis[i])==0时,这个r就是最优的.这个证明是01分数规划. #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #i…
题目链接 \(Description\) 将n个村庄连成一棵树,村之间的距离为两村的欧几里得距离,村之间的花费为海拔z的差,求花费和与长度和的最小比值 \(Solution\) 二分,假设mid为可行的某一生成树的解,则应有 \((∑cost)/(∑dis) = mid\) 变形得 \(\sum(cost-mid*dis) = 0\) 取cost-mid*dis为边权,Prim求最小生成树(即尽可能满足mid) 若\(\sum(cost-mid*dis) > 0\),说明怎么也满足不了mid,m…
题意: 给定n个村子的坐标(x,y)和高度z, 求出修n-1条路连通所有村子, 并且让 修路花费/修路长度 最少的值 两个村子修一条路, 修路花费 = abs(高度差), 修路长度 = 欧氏距离 分析: 01分数划分的题目, 构造出 d[i] = 修路花费 - L * 修路长度, 这个L值我们可以二分(这道题看数据范围的话二分上限其实挺大的, 但其实上限取到100就可以过), 也可以用Dinkelbach迭代出来. 二分(1422ms) #include <stdio.h> #include…
David the Great has just become the king of a desert country. To win the respect of his people, he decided to build channels all over his country to bring water to every village. Villages which are connected to his capital village will be watered. As…
Desert King http://poj.org/problem?id=2728 Time Limit: 3000MS   Memory Limit: 65536K       Description David the Great has just become the king of a desert country. To win the respect of his people, he decided to build channels all over his country t…
Desert King Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 20978   Accepted: 5898 [Description] David the Great has just become the king of a desert country. To win the respect of his people, he decided to build channels all over his co…
http://poj.org/problem?id=2728 题意: 在这么一个图中求一棵生成树,这棵树的单位长度的花费最小是多少? 思路: 最优比率生成树,也就是01分数规划,二分答案即可,题目很简单,因为这题是稠密图,所以用prim算法会好点. #include<iostream> #include<algorithm> #include<cstring> #include<cstdio> #include<vector> #include&…