hdu1162
#include<cstdio>
#include<cmath>
#include<climits>
#include<algorithm>
#define INF 1000000000
using namespace std;
struct p
{
double x,y;
}spot[110];
double cost[110][110];
double mincost[110];
bool used[110];
int n; double prim()
{
for(int i=0;i<n;i++)
{
mincost[i]=INF;
used[i]=false;
}
mincost[0]=0;
double res=0; while(true){
int v=-1;
for(int i=0;i<n;i++)
if(!used[i]&&(v==-1||mincost[i]<mincost[v])) v=i;
if(v==-1) break;
used[v]=true;
res+=mincost[v];
for(int i=0;i<n;i++)
mincost[i] = min(mincost[i], cost[v][i]); }
return res;
}
double dis(p a,p b)
{
double fa = (a.x-b.x);
double fb = (a.y-b.y);
return sqrt(fa*fa+fb*fb);
}
int main()
{
// int n;
while(~scanf("%d",&n))
{
for(int i=0;i<n;i++)
scanf("%lf%lf",&spot[i].x,&spot[i].y);
for(int i=0;i<n;i++)
for(int j=i;j<n;j++){
if(i==j) cost[i][j]=INF;
else { cost[i][j]=cost[j][i]=dis(spot[i],spot[j]); }
}
// for(int i=0;i<n;i++){
// for(int j=0;j<n;j++){
// printf("%lf ",cost[i][j]);
// }
// printf("\n");
// } printf("%.2lf\n",prim());
}
// printf("%lf",dis(spot[0],spot[1]));
return 0;
}
hdu1162的更多相关文章
- hdu1162(最小生成树 prim or kruscal)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1162 意义:给出一些点,用线问使所有点直接或间接连通,需要多长: 思路:裸最小生成树: 法1: pri ...
- 【HDU1162】Eddy's picture(MST基础题)
很基础的点坐标MST,一不留神就AC了, - - !! #include <iostream> #include <cstring> #include <cstdlib& ...
- hdu1162(最小生成树 prim or kruscal模板)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1162 意义:给出一些点,用线问使所有点直接或间接连通,需要多长: 思路:裸最小生成树: 法1: pri ...
- hdu-1162 Eddy's picture---浮点数的MST
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1162 题目大意: 给n个点,求MST权值 解题思路: 直接prim算法 #include<bi ...
- hdu1162 Eddy's picture 基础最小生成树
#include <cstdio> #include <cmath> #include <cstring> #include <algorithm> # ...
- Eddy's problem partI
Eddy's mistakes[HDU1161] Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java ...
- OJ题目分类
POJ题目分类 | POJ题目分类 | HDU题目分类 | ZOJ题目分类 | SOJ题目分类 | HOJ题目分类 | FOJ题目分类 | 模拟题: POJ1006 POJ1008 POJ1013 P ...
随机推荐
- react.js工程结构
1.index.html :UI界面入口.挂在点: 2.manifest.json:应用说明 3.package.json:工程说明.依赖说明等 4.source : 代码源文件
- 启动myeclipse弹窗Please allow Subclipse team to receive anonymous usage statistics for this Eclipse intance
Please allow Subclipse team to receive anonymous usage statistics for this Eclipse intance(翻译:请允许Sub ...
- 样例GeoQuiz应用开发 第1章
1. Activity是Android SDK的Activity类的一个具体实例,负责管理用户和信息屏的交互.应用的功能是通过编写一个Activity子类来实现的.简单的可能只有一个子类,复杂的应用则 ...
- 零基础入门学习Python(22)--函数:递归是神马
知识点 递归是神马? 递归是属于算法的范畴. 递归就是函数调用自身的一种行为. >>> def g(): return g() >>> g() Traceback ...
- 标量子查询中有ROWNUM=1怎么改?
碰到标量子查询中有ROWNUM=1怎么改? select to_date(o.postdate,'yyyymmdd'), (select cur.c_code from cur_tbl cur whe ...
- python3.x Day4 模块!!
json and pickle模块 用途是为了持久化信息,这种持久化方式可以和其他程序语言兼容,一般都支持json,json只能持久化数据,pickle是python特有的方式,可以持久化所有信息和数 ...
- Xshell连接Centos7.5和yum
目 录 第1章 Centos7 IP地址的配置 1 1.1 第一种配置ip方法(nmtui) 1 1.2 第二种 修改网卡配置文件 5 1.2.1 使用cat查看配置文件 5 ...
- c++基础_特殊的数字
#include <iostream> #include <math.h> using namespace std; int main(){ ;i<;i++){ ; )% ...
- 75-ADMI,Average Directional Movement Index,平均方向性运动指标.(2015.7.1)
ADMI,Average Directional Movement Index 平均方向性运动指标 Directional Movement Index,平均方向性运动指标.(2015.7.1)&qu ...
- [codevs4655] 序列终结者(Splay)
传送门 支持操作: 1.区间加 2.区间翻转 3.区间求最大值 splay模板 注意:update 里更新 max 时需要取 3 个值的 Max 别忘了各种边界讨论 ——代码 #include < ...