【HDU1875】畅通工程再续(MST基础题)
更改成实形数即可。第一次敲完直接交,CE了一次。晕。
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <numeric> #define typec double
using namespace std; const typec inf = 0xffff;
const int V = ;
int vis[V];
typec lowc[V], Map[V][V], point[V][]; typec prim (typec cost[][V], int n) {
int i, j, p;
typec minc, res = ;
memset(vis, , sizeof(vis));
vis[] = ;
for (i = ; i < n; ++ i) lowc[i] = cost[][i];
for (i = ; i < n; ++ i) {
minc = inf; p = -;
for (j = ; j < n; ++ j ) {
if ( == vis[j] && minc > lowc[j]) {
minc = lowc[j];
p = j;
}
}
if (inf == minc) return -;
res += minc;
vis[p] = ;
for (j = ; j < n; ++ j) {
if ( == vis[j] && lowc[j] > cost[p][j]) {
lowc[j] = cost[p][j];
}
}
}
return res;
} double cal_dis (double x1, double y1, double x2, double y2) {
return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
} int main () {
int T; scanf("%d", &T);
while (T --) {
//vector<pair<double, double> > p;
int n; scanf("%d", &n);
for (int i = ; i < n; ++ i) {
scanf("%lf%lf", &point[i][], &point[i][]);
} for (int i = ; i < ; ++ i) {
for (int j = ; j < ; ++ j) {
if (i == j) Map[i][j] = ;
else Map[i][j] = inf;
}
} for (int i = ; i < n; ++i) {
for (int j = i + ; j < n; ++ j) {
double w = cal_dis(point[i][], point[i][],point[j][],point[j][]);
if (w >= && w <= )
Map[i][j] = Map[j][i] = min(Map[i][j], w);
else continue;
/*cout << Map[i][j] << endl;
cout << Map[j][i] << endl;*/
}
} /*for (int i = 0; i < 2; ++ i) {
for (int j = 0 ; j < 2; ++ j) {
cout << Map[i][j] << " ";
}
cout << endl;
}*/
double ans = * prim(Map, n);
if (ans > )
printf("%.1lf\n", ans);
else {
printf("oh!\n");
}
//cout << prim (Map, n) << endl;
}
return ;
}
【HDU1875】畅通工程再续(MST基础题)的更多相关文章
- hdu-1875 畅通工程再续---MST
题目链接: https://vjudge.net/problem/HDU-1875 题目大意: 相信大家都听说一个“百岛湖”的地方吧,百岛湖的居民生活在不同的小岛中,当他们想去其他的小岛时都要通过划小 ...
- 【HDU1879】继续畅通工程(MST基础题)
真心大水题...不多说. #include <iostream> #include <cstring> #include <cstdlib> #include &l ...
- 【HDU1233】还是畅通工程(MST基础题)
无坑,裸题.直接敲就恩那个AC. #include <iostream> #include <cstring> #include <cstdio> #include ...
- hdu1875 畅通工程再续 暴力+基础最小生成树
#include<cstdio> #include<cmath> #include<algorithm> using namespace std; ; ; ; in ...
- HDU1875——畅通工程再续(最小生成树:Kruskal算法)
畅通工程再续 Description相信大家都听说一个“百岛湖”的地方吧,百岛湖的居民生活在不同的小岛中,当他们想去其他的小岛时都要通过划小船来实现.现在政府决定大力发展百岛湖,发展首先要解决的问题当 ...
- hdu1875 畅通工程再续 最小生成树并查集解决---kruskal
http://acm.hdu.edu.cn/showproblem.php?pid=1875 New~ 欢迎“热爱编程”的高考少年——报考杭州电子科技大学计算机学院关于2015年杭电ACM暑期集训队的 ...
- HDU1875 畅通工程再续 (并查集)
畅通工程再续 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Subm ...
- HDU1875 畅通工程再续 2017-04-12 19:52 48人阅读 评论(0) 收藏
畅通工程再续 Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Total Submis ...
- HDU1875 畅通工程再续
相信大家都听说一个“百岛湖”的地方吧,百岛湖的居民生活在不同的小岛中,当他们想去其他的小岛时都要通过划小船来实现.现在政府决定大力发展百岛湖,发展首先要解决的问题当然是交通问题,政府决定实现百岛湖的全 ...
- HDU-1875 畅通工程再续(最小生成树+判断是否存在)
http://acm.hdu.edu.cn/showproblem.php?pid=1875 Problem Description 相信大家都听说一个“百岛湖”的地方吧,百岛湖的居民生活在不同的小岛 ...
随机推荐
- membership source code
You can find their source code in codeplex at the ASP.NET source code. ExtendedMembershipProvider: h ...
- JAVA并发实现五(生产者和消费者模式Condition方式实现)
package com.subject01; import java.util.PriorityQueue; import java.util.concurrent.locks.Condition; ...
- poj 2836 Rectangular Covering(状态压缩dp)
Description n points are given on the Cartesian plane. Now you have to use some rectangles whose sid ...
- 为人们服务的asp.net 验证控件
ASP.NET是微软推出的WEB开发工具,他有很强大的功能,今天看视频讲到验证控件这一部分,真的感受到了微软全心全意为人民服务了.越来越佩服微软了,人家都设计出来了,咱们一定要会用才可以啊,不然太…. ...
- DOS命令大全--具体解释
在Linux和Windows下都能够用nslookup命令来查询域名的解析结果 DOS命令大全一)MD--建立子文件夹 1.功能:创建新的子文件夹 2.类型:内部命令 3.格式:MD[盘符:][路径名 ...
- vue 使用总结
1.Vuejs组件 vuejs构建组件使用 Vue.component('componentName',{ /*component*/ }): 这里注意一点,组件要先注册再使用,也就是说: Vue.c ...
- ie8 hack
1.‘\9’: eg:.test { color/*\**/: blue\9 }.header {width:300px;} /* 所有浏览器*/.header {width/*\**/:330px\ ...
- Android-------------获取手机IP地址
##帮助类PhoneNetStateUtil package com.funs.PhoneIPAddress.utils; /** * 手机联网状态工具类 需要的权限 WIFI时:</ ...
- php生成代金券码
<?php/** * @param int $no_of_codes//定义一个int类型的参数 用来确定生成多少个优惠码 * @param array $exclude_codes_array ...
- Linux Shell(初识)
什么是Shell:Shell是一个命令解释器. Linux下支持shell的种类: 1. Bourne Shell(简称sh) 2.C Shell(简称csh) 3.Korn Shell(简称ksh ...