玲珑学院OJ 1000 Spoon Devil's 3-D Matrix
来源:互联网 发布:ac尼尔森数据 编辑:程序博客网 时间:2024/04/25 19:37
【题目链接】http://www.ifrog.cc/acm/problem/1000
【解题方法】裸的最小生成树。
【AC 代码】
////Created by just_sort 2016/9/25 13:42//Copyright (c) 2016 just_sort.All Rights Reserved//#include <set>#include <map>#include <queue>#include <stack>#include <cmath>#include <cstdio>#include <cstdlib>#include <cstring>#include <iostream>#include <algorithm>using namespace std;typedef long long LL;const double inf = 1e18;int n;double g[55][55];double dis[55];bool vis[55];struct Point{ double x,y,z; void read(){ scanf("%lf%lf%lf",&x,&y,&z); }}p[55];double getdis(Point a,Point b){ return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)+(a.z-b.z)*(a.z-b.z));}int main(){ int T; scanf("%d",&T); while(T--){ scanf("%d",&n); for(int i=1; i<=n; i++) p[i].read(); for(int i=1; i<=n; i++) dis[i] = inf; for(int i=1; i<=n; i++) vis[i] = false; for(int i=1; i<=n; i++){ for(int j=1; j<=n; j++){ if(i==j) g[i][j] = inf; else g[i][j] = getdis(p[i],p[j]); } } double ans = 0; dis[1] = 0; for(int i=1; i<=n; i++){ int mark;double minn=inf; for(int j=1; j<=n; j++){ if(!vis[j] && dis[j]<minn){ minn = dis[j]; mark = j; } } vis[mark] = 1; ans += dis[mark]; for(int j=1; j<=n; j++){ if(!vis[j] && g[mark][j]<dis[j]){ dis[j] = g[mark][j]; } } } printf("%.2f\n",ans); } return 0;}
0 0
- 玲珑学院OJ 1000 Spoon Devil's 3-D Matrix
- 玲珑学院OJ 1000 - Spoon Devil's 3-D Matrix(3维最小生成树)
- Lonlife 1000 - Spoon Devil's 3-D Matrix
- Lonlife-ACM 1000 - Spoon Devil's 3-D Matrix(最小生成树)——“玲珑杯”acm比赛-试运行赛
- 玲珑学院OJ 1005 - Spoon Devil's RP Test(求余问题)
- 玲珑杯 1003 Spoon Devil's Diamond Mine
- 玲珑杯 1005 Spoon Devil's RP Test(水题)
- 玲珑杯 1009 Spoon Devil's Bucket 矩阵优化DP
- 玲珑杯1006 Spoon Devil Love Arithmetic
- 玲珑杯 1007 Spoon Devil Love Game
- Lonlife-ACM 1005 - Spoon Devil's RP Test(同余定理)——“玲珑杯”acm比赛-试运行赛
- 玲珑杯 1008 Spoon Devil Love Arithmetic Again
- 玲珑学院OJ 1126
- 玲珑学院OJ 1125
- 玲珑学院OJ 1131
- 玲珑学院OJ 1121
- 玲珑学院OJ 1130
- 玲珑学院oj Round#7
- Leetcode005--字符串中最大的回文子串
- 只要两行代码,就能判断一个App是否在前台运行
- 【Phalcon实现高性能接口开发】使用Phalcon高性能PHP框架搭建API MVC架构之实现查询版本的接口
- JAVA基础--JMM(二)
- 通知的应用
- 玲珑学院OJ 1000 Spoon Devil's 3-D Matrix
- 自定义控件其实很简单1/6
- QComboBox
- win10 截屏工具
- Android 6.0权限适配
- JAVA基础--JMM(一)
- 将React Native整合进Android项目超详细图文教程
- Spring基础学习--随笔1
- Thinking in java 学习笔记--chp01