题目链接:http://poj.org/problem?id=1251

字符用%s好了,方便一点。

#include <stdio.h>
#include <string.h> #define INF 0x3f3f3f3f int maps[][];
bool vis[];
int dis[];
int n; int Prim()
{
memset(vis,false,sizeof(vis));
for(int i=; i<=n; i++)
dis[i] = INF;
int ans=;
dis[] = ;
for(int i=; i<=n; i++)
{
int tmp = INF,k=;
for(int j=; j<=n; j++)
{
if(!vis[j]&&dis[j]<tmp)
{
tmp = dis[j];
k=j;
}
} vis[k] = true;
ans+=tmp;
for(int i=; i<=n; i++)
{
if(!vis[i]&&dis[i]>maps[k][i])
dis[i] = maps[k][i];
}
}
return ans;
} int main()
{
while(scanf("%d",&n),n)
{
for(int i=; i<=n; i++)
{
for(int j=; j<=n; j++)
if(i==j)
maps[i][j]=;
else maps[i][j] = INF;
}
for(int i=; i<n-; i++)
{
int t;
char a[],b[];
scanf("%s%d",a,&t);
for(int j=; j<t; j++)
{
int dist;
scanf("%s%d",b,&dist);
maps[a[]-'A'+][b[]-'A'+] = maps[b[]-'A'+][a[]-'A'+] = dist;
}
}
printf("%d\n",Prim());
}
return ;
}

Poj(1251),Prim字符的最小生成树的更多相关文章

  1. POJ 1251 Jungle Roads(最小生成树)

    题意  有n个村子  输入n  然后n-1行先输入村子的序号和与该村子相连的村子数t  后面依次输入t组s和tt s为村子序号 tt为与当前村子的距离  求链接全部村子的最短路径 还是裸的最小生成树咯 ...

  2. POJ 1251 Jungle Roads (最小生成树)

    题目: Description The Head Elder of the tropical island of Lagrishan has a problem. A burst of foreign ...

  3. POJ - 1251 Jungle Roads (最小生成树&并查集

    #include<iostream> #include<algorithm> using namespace std; ,tot=; const int N = 1e5; ]; ...

  4. poj 1251 Jungle Roads (最小生成树)

    poj   1251  Jungle Roads  (最小生成树) Link: http://poj.org/problem?id=1251 Jungle Roads Time Limit: 1000 ...

  5. POJ 1251 Jungle Roads (prim)

    D - Jungle Roads Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d & %I64u Su ...

  6. poj 1251 poj 1258 hdu 1863 poj 1287 poj 2421 hdu 1233 最小生成树模板题

    poj 1251  && hdu 1301 Sample Input 9 //n 结点数A 2 B 12 I 25B 3 C 10 H 40 I 8C 2 D 18 G 55D 1 E ...

  7. HDU-1233 还是畅通工程 (prim 算法求最小生成树)

    prim 算法求最小生成树 还是畅通工程 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Oth ...

  8. Prim和Kruskal最小生成树

    标题: Prim和Kruskal最小生成树时 限: 2000 ms内存限制: 15000 K总时限: 3000 ms描述: 给出一个矩阵,要求以矩阵方式单步输出生成过程.要求先输出Prim生成过程,再 ...

  9. Kruskal和Prim算法求最小生成树

    Kruskal算法求最小生成树 测试数据: 5 6 0 1 5 0 2 3 1 2 4 2 4 2 2 3 1 1 4 1 输出: 2 3 1 1 4 1 2 4 2 0 2 3 思路:在保证不产生回 ...

随机推荐

  1. jquery ui dialog去掉右上角的叉号

    var dialog = $("#id").dialog({ resizable:false, height:, width:, zIndex:, modal:true, open ...

  2. CSS3部分新特性

    1.旋转transform:rotate(30deg);-ms-transform:rotate(30deg); /* IE 9 */-moz-transform:rotate(30deg); /* ...

  3. java容器学习

    容器是java中重要的一部分,其接口的结构如下 Collection | ------------------ Map | | | Set List HashMap | HashSet 顾名思义,容器 ...

  4. Greenplum 集群部署

    最近开始接触Greenplum,线上也在使用了,感觉还不错,本次介绍一下集群的部署方法.那么Greenplum的架构如下: (架构图来源网络) 简单来说GPDB是一个分布式数据库软件,其可以管理和处理 ...

  5. Server.UrlEncode与Server.UrlDecode(url传递中文的解决方案)

    1.设置web.config文件.<system.web> ...... <globalization requestEncoding="gb2312" resp ...

  6. 【iCore3 双核心板】例程二十:LAN_TCPC实验——以太网数据传输

    实验指导书及代码包下载: http://pan.baidu.com/s/1pJY5uXH iCore3 购买链接: https://item.taobao.com/item.htm?id=524229 ...

  7. Codevs 1299 切水果

    题目链接 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 大师 Master 题目描述 Description 简单的说,一共N个水果排成一排,切M次,每次切[L,R]区间的所有水果 ...

  8. Apply 与 Call 的用法(简化版)

    Javascript中Apply 与 Call 的用法,这里只作简单的入门说明 function human( name, age ){ this.name = name; this.age = ag ...

  9. ssm框架中的struts我的配置问题

    <?xml version="1.0" encoding="UTF-8" ?>  <!DOCTYPE struts PUBLIC    &qu ...

  10. iOS:Xcode8以下真机测试iOS10.0和iOS10.1配置包

    一.介绍 xcode的升级都已经到8系列了,可是还是有很多开发者使用的xcode还是7系列,然而xcode7...最多支持9.3,无法给升级到10.0和10.1的iPhone手机用户进行真机测试.此时 ...