zoj 1203 Swordfish MST

很简单的MST,用prim写的,把初始化和维护写在了一起。

/*
author:jxy
lang:C/C++
university:China,Xidian University
**If you need to reprint,please indicate the source**
*/
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#define INF 1E9
using namespace std;
struct node
{
    double x,y;
};
double d(node a,node b)
{
    return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
node place[101];
bool vis[101];
double dis[101];
int main()
{
    int n,C=0;
    while(~scanf("%d",&n)&&n)
    {
        if(C)puts("");
        C++;
        memset(vis,0,sizeof(vis));
        memset(dis,127,sizeof(dis));
        int i,j;
        for(i=0;i<n;i++)
          scanf("%lf%lf",&place[i].x,&place[i].y);
        double ans=0,Min,t;
        int now=0;
        for(i=0;i<n;i++)
        {
            Min=INF;
            for(j=0;j<n;j++)
            {
                if(dis[j]>=Min||vis[j])continue;
                Min=dis[j];now=j;
            }
            vis[now]=1;
            if(now)ans+=Min;
            for(j=0;j<n;j++)
            {
                if(vis[j])continue;
                dis[j]=min(dis[j],d(place[now],place[j]));
            }

        }
        printf("Case #%d:\nThe minimal distance is: %.2f\n",C,ans);
    }
}
时间: 2024-09-20 00:19:15

zoj 1203 Swordfish MST的相关文章

ZOJ和PKU 题目分类

ZOJ题目分类初学者题: 1001 1037 1048 1049 1051 1067 1115 1151 1201 1205 1216 1240 1241 1242 1251 1292 1331 1334 1337 1338 1350 1365 1382 1383 1394 1402 1405 1414 1494 1514 1622 1715 1730 1755 1760 1763 1796 1813 1879 1889 1904 1915 1949 2001 2022 2099 2104 21

GW MST+DXC使用记

随着通信业务的不断丰富,越来越多的用户需要租用电信运营商的网络资源来进行各种业务的通信或组建专网:中国加入WTO将会进一步并更深入的引进竞争机制,不仅将引起国内新兴电信运营商和传统电信运营商之间的竞争,同时还会引发与国外相应的业务提供商之间的竞争,因此在向用户提供业务和服务方面,谁提供的业务种类更全面.质量更可靠.服务更有保障,谁就会更有竞争优势,并更能在市场竞争中立于不败之地. 格林威尔科技发展有限公司研发的GW MST系列综合业务复用设备就是为各大电信运营商及新兴运营商面向多种业务综合接入的

通过组策略部署symantec client (MST格式)

通过组策略部署symantec client (MST格式) 近期公司要求用户都安装symantec client,我们当前的版本是Endpoint protection 12.1.100,这样一来我们大家都会想到的是通过组策略部署软件分发到每个域用户计算机上:当然我们大家也知道,微软去年发布了windows8系统,但是我们在windows8上安装symantec client后无法正常打开或无法运行,经过跟symantec沟通说是目前symantec的版本跟windows8不兼容,需要syma

poj 1679 The Unique MST:次小生成树

链接: http://poj.org/problem?id=1679 题目: Description Given a connected undirected graph, tell if its minimum spanning tree is unique. Definition 1 (Spanning Tree): Consider a connected, undirected graph G = (V, E). A spanning tree of G is a subgraph of

zoj 3261 Connections in Galaxy War:逆向并查集

链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3261 题目: Connections in Galaxy War Time Limit: 3 Seconds      Memory Limit: 32768 KB In order to strengthen the defense ability, many stars in galaxy allied together and built many bidi

UVa 10038 / POJ 2575 / ZOJ 1879 Jolly Jumpers (water ver.)

10038 - Jolly Jumpers Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=979 http://poj.org/problem?id=2575 http://acm.zju.edu.cn/onlinejudge/showProblem.do?

算法:zoj 3201 Tree of Tree(树形背包dp)

题意 给一棵节点带权的树,找到一个有k个节点的子树,求这个子树的最大权值 思路 树形 dp+背包. f(i, j) 表示以i为根节点的有j个节点子树的最大权值 然后对i的每个子节点做分组背包, 因为对于i的每个儿子,可以选择分配 1,2,3...j-1个节点给它 f(i, j) = max{ max{f(i, j-p) + f(v, p) | 1<=p<j} | v是i的儿子节点} ans = max{ f[i][k] | 0<=i<n && i 子树节点个数>

UVa 575 / ZOJ 1712 / Mid-Central USA 1997 Skew Binary

UVa 575 / ZOJ 1712 / Mid-Central USA 1997 Skew Binary (water ver.&斜二进制) 575 - Skew Binary Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php? option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=516 http://

算法:ZOJ 3659 Conquer a New Region(并查集)

[题目大意] 有N个城市,N-1条路把这些城市连起来(刚好是一个树).相邻的两个城市有一个 运输容量C(i, j),而城市x到城市y的那条路的运输能力S取决与这条路上所经过的所有路中最小的那个容量 . 以那一个城市为中心,到其他N-1个城市的运输能力总和最大? [思路] 用神奇的并查集 ,把路按照权值从大到小排序,然后用类似Kruskal的方法不断的加入边. 对于要加入的一条路,这条路连 接这城市x和y,x所在的集合为A, y所在的集合为B, 可以确定A,B集合内的所有路都比当前这条路的权值 大