【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 相信大家都听说一个“百岛湖”的地方吧,百岛湖的居民生活在不同的小岛 ...
随机推荐
- springmvc+mongodb+maven 项目搭建配置
操作步骤我就不再细化了 项目能运行,测试过了,先上配置,另一篇文章上代码,点击下载源码 项目结构 pom.xml <project xmlns="http://maven.apache ...
- js原型和原型链个人理解(我的理解)
<script> //普通对象与函数对象,js万物皆是对象 //自带的 function a1() { function f1() {} var f2=function () {} var ...
- How to face setbacks
I’ve been in a bad mood since I started on the American Accent. I became even more upset when I adde ...
- hdu4000 && hrbust1625
ikki的数字 Time Limit: 1000 MS Memory Limit: 32768 K Total Submit: 22(12 users) Total Accepted: 9(8 use ...
- swift2.0 UIImagePickerController 拍照 相册 录像
系统 ios9.1 语言swift2.0 在app 里最常用的功能就是多媒体选择,首先我们storyboard 创建一个button 用于触发选择事件 @IBAction func selectIma ...
- [.NET | 發佈] 如何指定固定的目錄給程式調用的外部DLL?
1.OverView 一般程式只會查找與主程式同目錄的DLL檔案 解決方案主要可以參考這篇:http://support.microsoft.com/kb/837908 2.實作app.config方 ...
- [MVC4-基礎] 使用DataAnnotations+jQuery進行表單驗證
我目前有以下表單,Select部分因為必須上一層有選擇下層才有資料,因此使用jQuery驗證問題類型是否有選擇就好,而問題描述要驗證是否為空,這裡採用MVC內建的DataAnnotations來驗證. ...
- javascript构造函数+原形继承+作用域扩充
目前为止我认为这是最佳的声明对象的模式,将今天学到的东西写下 <script type="text/javascript"> function Constructor( ...
- VS2010 ReportViewer导出文件下载保存不能识别文件类型
今天测试项目时,突然发现导出报表下载保存的保存,不能识别文件的类型,文件名称为:.xls[3] 检查代码发现在指定报表路径时多了一个方法: ReportViewer1.LocalReport.Load ...
- StartService与BindService
效果图 MainActivity.java package com.wangzhen.servicedemo; import com.lidroid.xutils.ViewUtils; import ...