Poj(1251),Prim字符的最小生成树
题目链接: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字符的最小生成树的更多相关文章
- POJ 1251 Jungle Roads(最小生成树)
题意 有n个村子 输入n 然后n-1行先输入村子的序号和与该村子相连的村子数t 后面依次输入t组s和tt s为村子序号 tt为与当前村子的距离 求链接全部村子的最短路径 还是裸的最小生成树咯 ...
- POJ 1251 Jungle Roads (最小生成树)
题目: Description The Head Elder of the tropical island of Lagrishan has a problem. A burst of foreign ...
- POJ - 1251 Jungle Roads (最小生成树&并查集
#include<iostream> #include<algorithm> using namespace std; ,tot=; const int N = 1e5; ]; ...
- poj 1251 Jungle Roads (最小生成树)
poj 1251 Jungle Roads (最小生成树) Link: http://poj.org/problem?id=1251 Jungle Roads Time Limit: 1000 ...
- POJ 1251 Jungle Roads (prim)
D - Jungle Roads Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & %I64u Su ...
- 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 ...
- HDU-1233 还是畅通工程 (prim 算法求最小生成树)
prim 算法求最小生成树 还是畅通工程 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Oth ...
- Prim和Kruskal最小生成树
标题: Prim和Kruskal最小生成树时 限: 2000 ms内存限制: 15000 K总时限: 3000 ms描述: 给出一个矩阵,要求以矩阵方式单步输出生成过程.要求先输出Prim生成过程,再 ...
- 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 思路:在保证不产生回 ...
随机推荐
- 汇编基础知识之二debug的使用
DEBUG的使用 (要在win32位习题下进行,win7 64位需要安装DosBox和debug这2个软件): 1:win64位下debug的使用教程: 下载debug.exe,这里我把debug放在 ...
- CentOs5.8下安装Oracle12C
12C安装向导: http://docs.oracle.com/database/121/LTDQI/toc.htm 12C下载地址: http://www.oracle.com/technetwor ...
- Sql Server按树形结构排序查询表记录
http://blog.csdn.net/dxnn520/article/details/8089149 ----------------------------------------------- ...
- NYOJ背包问题
#include <stdio.h> struct group{ int value; int weight; }; void Sort(group bag[],int num) { in ...
- matplotlib 安装与使用
1.在ubuntu下输入 sudo apt-get install python-matplotlib 安装matplotlib 2.简单代码使用
- angularJs表单校验(超级详细!!!)
html代码 <!DOCTYPE html> <html ng-app="angularFormCheckModule"> <head> < ...
- spring log4j.properties 没有日志的问题
一. log4j.properties 1. log4j.properties放在spring工程的src/main/rescours目录下无法读取. 测试后发现需要把log4j.properti ...
- JS判断终端设备跳转PC端、移动端相应的URL
<!DOCTYPE html> <html> <head> <meta charset=" utf-8"> <meta nam ...
- TP框架知识点
- 一个支持FMX.Win框架的托盘控件
不多说了 直接上代码........有任何问题请给我邮件.... // **************************************************************** ...