【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 相信大家都听说一个“百岛湖”的地方吧,百岛湖的居民生活在不同的小岛 ...
随机推荐
- Linux中open函数以及退出进程的函数
open函数的flag详解1 读写权限:O_RDONLY O_WRONLY O_RDWR (1)linux中文件有读写权限,我们在open打开文件时也可以附带一定的权限说明 (譬如O_RDONLY就表 ...
- 马士兵 Servlet & JSP(1) Servlet (源代码)
1.HTTP协议基础测试(获取页面源代码) import java.io.BufferedReader; import java.io.IOException; import java.io.Inpu ...
- poj 2046 Gap(bfs+hash)
Description Let's play a card game called Gap. You have cards labeled with two-digit numbers. The fi ...
- git hub 资料汇总
tobecrazy Selenium automation test framework https://github.com/tobecrazy/Demo Smartphone Test F ...
- Java操作属性文件,支持新增或更新多个属性
Java操作属性文件.支持新增或更新多个属性 一.更新或新增单个属性的方法 /** * 写入properties信息 * @param filePath 绝对路径(包含文件名称和后缀名) * @par ...
- UVA 10400 Game Show Math (dfs + 记忆化搜索)
Problem H Game Show Math Input: standard input Output: standard output Time Limit: 15 seconds A game ...
- DB2查询当前时间与指定时间的时间差(相隔的秒数)
DB2查询当前时间与指定时间的时间差(相隔的秒数). 例子:“拍品表 auct_item”中有个“结束时间 end_date”的字段,求结束时间与当前时间的间隔秒数. select (DAYS(a. ...
- 如何实现带照片缩略图的Listview
ackage com.demo; import java.util.ArrayList; import android.app.Activity; import android.content.Con ...
- angularJS自定义过滤器、服务和指令
自定义过滤器 mainApp.filter('mayfilter',function(){ return function(input){ (过滤逻辑代码) } }); 自定义创建指令 mainA ...
- 设置c#windows服务描述及允许服务与桌面交互的几种方法(转)
方法一: 在ProjectInstaller.cs重写 install() ,Uninstall()方法 public override void Install(IDictionary stateS ...