原题:
Description
You are the owner of SmallCableCo and havepurchased the franchise rights for a small town. Unfortunately, youlack enough funds to start your business properly and are relyingon parts you have found in an old warehouse you bought. Among yourfinds is a single spool of cable and a lot of connectors. You wantto figure out whether you have enough cable to connect every housein town. You have a map of town with the distances for all thepaths you may use to run your cable between the houses. You want tocalculate the shortest length of cable you must have to connect allof the houses together.
Input
Only one town will be given in aninput.
< house name A > <house name B > < distance>
Where the two house names match two different names in the listabove and the distance is a positive real number. There will not betwo paths between the same pair of houses.
- The first line gives the length of cable on the spool as a realnumber.
- The second line contains the number of houses,N
- The next N lines give the name of each house's owner. Each nameconsists of up to 20 characters {a–z,A–Z,0–9} and contains nowhitespace or punctuation.
- Next line: M, number of paths betweenhouses
- next M lines in the form
< house name A > <house name B > < distance>
Where the two house names match two different names in the listabove and the distance is a positive real number. There will not betwo paths between the same pair of houses.
Output
The output will consist of a single line. If thereis not enough cable to connect all of the houses in the town,output
Not enough cable
If there is enough cable, then output
Need < X > miles ofcable
Print X to the nearest tenth of a mile (0.1).
Not enough cable
If there is enough cable, then output
Need < X > miles ofcable
Print X to the nearest tenth of a mile (0.1).
Sample Input
100.0 4 Jones Smiths Howards Wangs 5 Jones Smiths 2.0 Jones Howards 4.2 Jones Wangs 6.7 Howards Wangs 4.0 Smiths Wangs 10.0
Sample Output
Need 10.2 miles of cable
大意:在n个房屋之间铺设缆线,要求总长度尽量短;
思路:裸的最小生成树,目测房屋所构的图比较稀疏,用并查集加堆容易写。由于输入的是字符串,所以用map将字符串和房屋序号绑定,利于以后代码的计算。。。。
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <stdio.h>
#define inf 0x6FFFFFFF
using namespace std;
struct point
{
};
bool operator<(point a,point b)
{
}
priority_queue<point> que;
map<string ,int > maps;
double sum;
int parent[500];
int n;
int getparent(int k)
{
}
int main()
{
}