poj 2485 prim入门题目
来源:互联网 发布:mac怎么保存文档 编辑:程序博客网 时间:2024/05/29 07:29
Highways
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 30601 Accepted: 13910
Description
The island nation of Flatopia is perfectly flat. Unfortunately, Flatopia has no public highways. So the traffic is difficult in Flatopia. The Flatopian government is aware of this problem. They're planning to build some highways so that it will be possible to drive between any pair of towns without leaving the highway system.
Flatopian towns are numbered from 1 to N. Each highway connects exactly two towns. All highways follow straight lines. All highways can be used in both directions. Highways can freely cross each other, but a driver can only switch between highways at a town that is located at the end of both highways.
The Flatopian government wants to minimize the length of the longest highway to be built. However, they want to guarantee that every town is highway-reachable from every other town.
Flatopian towns are numbered from 1 to N. Each highway connects exactly two towns. All highways follow straight lines. All highways can be used in both directions. Highways can freely cross each other, but a driver can only switch between highways at a town that is located at the end of both highways.
The Flatopian government wants to minimize the length of the longest highway to be built. However, they want to guarantee that every town is highway-reachable from every other town.
Input
The first line of input is an integer T, which tells how many test cases followed.
The first line of each case is an integer N (3 <= N <= 500), which is the number of villages. Then come N lines, the i-th of which contains N integers, and the j-th of these N integers is the distance (the distance should be an integer within [1, 65536]) between village i and village j. There is an empty line after each test case.
The first line of each case is an integer N (3 <= N <= 500), which is the number of villages. Then come N lines, the i-th of which contains N integers, and the j-th of these N integers is the distance (the distance should be an integer within [1, 65536]) between village i and village j. There is an empty line after each test case.
Output
For each test case, you should output a line contains an integer, which is the length of the longest road to be built such that all the villages are connected, and this value is minimum.
复习一下prim算法
#include <stdio.h>#include <string.h>#include <algorithm>#include <math.h>using namespace std;const int INF = 0x3f3f3f3f;const int maxd = 502;int map[maxd][maxd];bool vis[maxd];int low[maxd];int N;void prim(){int max = 0;memset(vis,false,sizeof(vis));memset(low,0,sizeof(low));vis[0] = true;for(int i = 1; i < N; i++){low[i] = map[0][i];}for(int i = 1; i < N; i++){int min = INF, temp,k;for(int j = 1; j < N; j++){if(!vis[j] && min > low[j]){min = low[j];k = j;}}vis[k] = true;if(max < min){max = min;}for(int j = 1; j < N; j++){if(low[j] >map[k][j] && !vis[j]){low[j] = map[k][j];}}}printf("%d\n",max);}int main(){int T;scanf("%d",&T);while(T--){scanf("%d",&N);int x;for(int i = 0; i < N; i++){for(int j = 0; j < N; j++){scanf("%d",&x);map[i][j] = x;}}prim();}return 0;}
0 0
- poj 2485 prim入门题目
- poj 2485 Prim
- POJ 2485 Prim
- 【prim】poj 2485
- poj 2485 prim
- Highways POJ 2485【Prim】
- poj 2485 Highways ( prim )
- poj 2485 Highways(prim)
- POJ 2485 Highways (kruskal+prim)
- POJ 2485 Highways (MST.Prim)
- POJ 2485(prim 算法)
- poj 2485 (Prim简单题)
- POJ 2485 Highways(prim算法)
- poj 2485(最小生成树 Prim)
- poj 2485 highways(prim)
- poj 2485 Highways prim最小生成树
- poj 2485(prim最小生成树)
- POJ 2485 Highways (prim最小生成树)
- PL/SQL 显式游标
- offsetHeight、offsetWidth、clientWidth、clientHeight无法获取值得问题
- 有些时候,有些判断是无法做到真实,但是能做到最优也不错了
- 来谈谈SQL数据库中"简单的"SELECT TOP—可能有你从未注意到的细节
- JAVA动态代理的理解(转载)
- poj 2485 prim入门题目
- 杭电oj(Java版)——1720 A+B Coming
- CSS样式的优先级
- 粉丝经济新时代来临,商虫云微信群控系统的商机你看到...
- tp ajax 搜索分页
- XZ_iOS之app分享到QQ或者微信,然后点击分享链接调起app
- 杭电oj(Java版)——1722 Cake
- 如何生成id_dsa.pub?
- PAT_1031. Hello World for U