poj2075
Time Limit: 1000MS | Memory Limit: 30000K | |
Total Submissions: 6348 | Accepted: 2505 |
Description
Input
- The first line gives the length of cable on the spool as a real number.
- The second line contains the number of houses, N
- The next N lines give the name of each house's owner. Each name consists of
up to 20 characters {a–z,A–Z,0–9} and contains no whitespace or punctuation. - Next line: M, number of paths between houses
- next M lines in the form
< house name A > < house name
B > < distance >
Where the two house names match two different
names in the list above and the distance is a positive real number. There will
not be two paths between the same pair of houses.
Output
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 of
cable
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
Source
POJ2075 Tangled in Cables 最小生成树
题目大意:
给你一些人名,然后给你n条连接这些人名所拥有的房子的路,求用最小的代价求连接这些房子的花费是否满足要求。
#include<cstdio>
#include<cstring>
#include<string>
#include<map>
#include<algorithm>
#include<iostream>
using namespace std;
#define N 15010
map<string,int>ad;
struct node{
int x,y;
double v;
node(int x=,int y=,double v=):x(x),y(y),v(v){}
}e[N];
int n,m,fa[N];double money;
int find(int x){
return fa[x]==x?x:fa[x]=find(fa[x]);
}
bool cmp(const node &a,const node &b){
return a.v<b.v;
}
int main(){
freopen("sh.in","r",stdin);
scanf("%lf%d",&money,&n);
for(int i=;i<=n;i++){
char str[];
scanf("%s",str);
ad[str]=i;
}
scanf("%d",&m);
for(int i=;i<=m;i++){
char c1[],c2[];
double cost;
scanf("%s %s %lf",c1,c2,&cost);
e[i].x=ad[c1];
e[i].y=ad[c2];
e[i].v=cost;
}
sort(e+,e+m+,cmp);
double ans=;int k=;
for(int i=;i<=n;i++) fa[i]=i;
for(int i=;i<=m;i++){
int fx=find(e[i].x),fy=find(e[i].y);
if(fx!=fy){
fa[fy]=fx;
ans+=e[i].v;
k++;
}
if(k==n-) break;
}
if(money>ans) printf("Need %.1lf miles of cable\n",ans);
else printf("Not enough cable\n");
return ;
}
poj2075的更多相关文章
- OJ题目分类
POJ题目分类 | POJ题目分类 | HDU题目分类 | ZOJ题目分类 | SOJ题目分类 | HOJ题目分类 | FOJ题目分类 | 模拟题: POJ1006 POJ1008 POJ1013 P ...
随机推荐
- python 时间 相关
http://www.jb51.net/article/47957.htm 不管何时何地,只要我们编程时遇到了跟时间有关的问题,都要想到 datetime 和 time 标准库模块,今天我们就用它内部 ...
- Android应用程序窗体设计框架介绍
在Android系统中,一个Activity相应一个应用程序窗体.不论什么一个Activity的启动都是由AMS服务和应用程序进程相互配合来完毕的.AMS服务统一调度系统中全部进程的Activity启 ...
- ElasticSearch 排序
1.相关性排序 ElasticSearch为了按照相关性来排序,需要将相关性表示为一个数值,在 Elasticsearch 中, 相关性得分 由一个浮点数进行表示,并在搜索结果中通过 _score 参 ...
- dmz主机就是DNAT功能的体现
端口映射和DMZ是提供内网和外网映射的,具体各自如下:DMZ:就相当于DNAT(Destination NAT),只对目的IP地址做地址转换.也就是说,收到目的IP为自己WAN口的包,统统转发给内网的 ...
- 不是书评 :《我是一只IT小小鸟》
本文转自刘未鹏 博客,写的非常的好 就转回来了 设计你自己的进度条 进度条的设计是一个很多人都知道的故事:同样的耗时,如果不给任何进度提示,只是在完成之后才弹出一个完成消息,中间没有任何动态变化,那么 ...
- JSP 基于Oracle分页
booklist.jsp <%@page import="books.accp.utils.Pager"%> <%@page import="books ...
- react-native Android 全面屏手机 底部留有一大块黑屏
解决方案:在AndroidManifest.xml 中 配置 <meta-data android:name="android.max_aspect" android:val ...
- d3系列2--api攻坚战05
今天的内容相比之前的就有点儿难了?怂了没? 别问我为什么不讲详细内容,你写十遍自己就清楚究竟是怎么回事了,画画的事儿还是得动笔动键盘. 先看看效果图 事实上假设用笨办法一条一条画的话.也不难. 可是设 ...
- 51单片机 | 使用D/A转换器实现三角波发生器
———————————————————————————————————————————— D/A转换器 CS=0.ILE=1时,WR1信号有效时将数据总线上的信号写入8位输入锁存器 XFER=0时,W ...
- MongoDB 常见的查询索引
常见的查询索引 _id索引 _id 索引是绝大多数集合默认建立的索引.对于每一个插入的数据.MongoDB 会自己主动生成一条唯一的 _id 字段. 1 2 3 4 5 6 7 8 9 ...