题目链接: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. 定位position

    position : absolute | relative | fixed | static 定位:子集可以超出父级的范围,如父级蛇overflow:hidden则看不到. absolute : 绝 ...

  2. JAVA6开发WebService (三)——几个概念

    转载自http://wuhongyu.iteye.com/blog/808922 要了解WebService,光能写代码不行啊,这说说WebService最基本的概念. 首先WebService要知道 ...

  3. Xilinx SDK Problem Solution in Ubuntu

    Problem1: Documention and Example can't open, Xilinx SDK  Ubuntu.   Step1: Click the Document link o ...

  4. 【iCore3 双核心板_ uC/OS-III】例程一:认识 uC/OS-III

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

  5. DS Tree 已知后序、中序 => 建树 => 求先序

    注意点: 和上一篇的DS Tree 已知先序.中序 => 建树 => 求后序差不多,注意的地方是在aftorder中找根节点的时候,是从右往左找,因此递归的时候注意参数,最好是拿纸和笔模拟 ...

  6. 获取外部配置JDBC文件 写给自己

    web项目要把配置放在WEB下 内容 Driver=com.microsoft.sqlserver.jdbc.SQLServerDriverurl=jdbc:sqlserver://192.168.3 ...

  7. Tomcat调优

    问题定位 对于Tomcat的处理耗时较长的问题主要有当时的并发量.session数.内存及内存的回收等几个方面造成的.出现问题之后就要进行分析了. 1.关于Tomcat的session数目 这个可以直 ...

  8. 【ionic】Mac IOS下真机调试

    模拟调试不能保证真机一定没问题,所以真机调试是非常必要的一步 IOS设备 启用设备调试 在IOS设备中(Iphone,Ipad)中开始web检测器 设备->safari->高级->w ...

  9. ES6 module export options 模块导出、导入语法

    http://stackoverflow.com/questions/25494365/es6-module-export-options A year and some later, here is ...

  10. 多线程 - CountDownLatch

    一个同步辅助类,在完成一组正在其他线程中执行的操作之前,它允许一个或多个线程一直等待. 用给定的计数 初始化 CountDownLatch.由于调用了 countDown() 方法,所以在当前计数到达 ...