poj2485
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 27912 | Accepted: 12734 |
Description
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
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.
Output
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.
Sample Input
1 3
0 990 692
990 0 179
692 179 0
Sample Output
692
Hint
Source
题意:Flatopia岛要修路,这个岛上有n个城市,要求修完路后,各城市之间可以相互到达,且修的总
路程最短.
求所修路中的最长的路段
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
#define N 510
struct node{
int x,y,v;
}e[N*N];
int t,fa[N];
bool cmp(const node &a,const node &b){
return a.v<b.v;
}
int find(int x){
return fa[x]==x?x:fa[x]=find(fa[x]);
}
int main(){
scanf("%d",&t);
while(t--){
int n,cnt=;
scanf("%d",&n);
for(int i=;i<=n;i++) fa[i]=i;
for(int i=;i<=n;i++){
for(int j=;j<=n;j++){
int x;
scanf("%d",&x);
if(x){
e[++cnt].x=i;e[cnt].y=j;e[cnt].v=x;
}
}
}
int k=,res=;
sort(e+,e+cnt+,cmp);
for(int i=;i<=cnt;i++){
int fx=find(e[i].x),fy=find(e[i].y);
if(fx!=fy){
fa[fy]=fx;
k++;
}
if(k==n-){
res=e[i].v;//因为排完序了,所以最后一个就是最大的
break;
}
}
printf("%d\n",res);
for(int i=;i<=n;i++) fa[i]=;//养成清零好习惯
for(int i=;i<=n;i++) e[i]=e[];
}
return ;
}
poj2485的更多相关文章
- poj2485&&poj2395 kruskal
题意:最小生成树的最大边最小,sort从小到大即可 poj2485 #include<stdio.h> #include<string.h> #include<algor ...
- POJ2485 最小生成树
问题:POJ2485 本题求解生成树最大边的最小值 分析: 首先证明生成树最大边的最小值即最小生成树的最大边. 假设:生成树最大边的最小值比最小生成树的最大边更小. 不妨设C为G的一个最小生成树,e是 ...
- POJ-2485 Highways---最小生成树中最大边
题目链接: https://vjudge.net/problem/POJ-2485 题目大意: 求最小生成树中的最大边 思路: 是稠密图,用prim更好,但是规模不大,kruskal也可以过 #inc ...
- 最小生成树Prim poj1258 poj2485 poj1789
poj:1258 Agri-Net Time Limit: 1000 MS Memory Limit: 10000 KB 64-bit integer IO format: %I64d , %I64u ...
- poj2485 kruskal与prim
Kruskal: #include<iostream> #include<cstdio> #include<algorithm> using namespace s ...
- poj2485 Highways
Description The island nation of Flatopia is perfectly flat. Unfortunately, Flatopia has no public h ...
- POJ2485 Highways(最小生成树)
题目链接. 分析: 比POJ2253要简单些. AC代码: #include <iostream> #include <cstdio> #include <cstring ...
- POJ2485——Highways
Description The island nation of Flatopia is perfectly flat. Unfortunately, Flatopia has no public h ...
- poj2485 highwaysC语言编写
/*HighwaysTime Limit: 1000MSMemory Limit: 65536KTotal Submissions: 33595Accepted: 15194DescriptionTh ...
- POJ2485:Highways(模板题)
http://poj.org/problem?id=2485 Description The island nation of Flatopia is perfectly flat. Unfortun ...
随机推荐
- 开源 java CMS - FreeCMS2.3会员我的留言
原文地址:http://javaz.cn/site/javaz/site_study/info/2015/29631.html 项目地址:http://www.freeteam.cn/ 我的留言 从 ...
- 利用excel去除txt文本中重复项
2017-04-10 1.要去重的文件,点击右键,选择程序. 2.选择excel表格或者wps表格. 3.excel表格去重:选中单元格——数据——筛选——高级筛选——选择不重复记录——确定 wps表 ...
- shell中字符串截取
Linux 的字符串截取很有用.有八种方法. 假设有变量 var="User:123//321:/home/dir" 1. # 号截取,删除左边字符,保留右边字符. [root@z ...
- Codeforces 463C Gargari and Bishops 题解
题目出处: http://codeforces.com/contest/463/problem/C 感觉本题还是挺难的.须要好好总结一下. 计算对角线的公式: 1 右斜对角线,也叫主对角线的下标计算公 ...
- 【Excle数据透视表】如何水平并排显示报表筛选区域的字段
原始效果 目标效果 解决方案 设置数据透视表"在报表区域筛选显示字段"为"水平并排" 步骤 方法① 单击数据透视表任意单元格→数据透视表工具→分析→选项→布局和 ...
- PDF快速创建目录
很多从网上直接下载的PDF电子书目录都不全,因此搜索资料又加以改化,总结了一个自己手动快速创建目录的办法,分享给大家. 百度搜索PDF电子书的目录或者直接从PDF拷贝到Notepad++等编辑器,使用 ...
- android 语音识别
Android中主要通过RecognizerIntent来实现语音识别,事实上代码比較简单.可是假设找不到设置,就会抛出异常ActivityNotFoundException.所以我们须要捕捉这个异常 ...
- ThinkPad E430C从待机状态恢复后,无线网络就不可用了
奇妙的问题,ThinkPad E430C从待机状态恢复后.无线网络就不可用了. Windows7系统.按Fn+F8或F7能够调节屏幕亮度,可是F9+Fn也没反应. 把驱动卸载了又一次安装了也无论用,W ...
- Atitit.业务系统的新特性 开发平台 新特性的来源总结
Atitit.业务系统的新特性 开发平台 新特性的来源总结 1.1. 语言新特性(java c# php js python lisp c++ oc swift ruby go dart1 1.2. ...
- 自动测试工具agitarOne 初体验之-MockingBird的使用
大名鼎鼎的AgitarOne就不用解释了,在昨天的随笔中有一些解释,今天主要说说Agitar 中Mockingbird的使用. 为了提高测试代 码的Coverage,仅仅靠Agita ...