黑龙江快乐十分

poj-2485 Highways

3/8/2017来源:ASP.NET技巧人气:20834

highways time limit: 1000ms memory limit: 65536k total submissions: 30003 accepted: 13656 descrtion

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 oblem. 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. 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. 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. sample input

1

3 0 990 692 990 0 179 692 179 0

sample output

692

hint

huge input,scanf is recommended.

黑龙江快乐十分miaoshu :yougechengshijiaozuohshi。qizhongyouhenduogecunzhuang,cunzhuangzhijiantongxinjibenkaohou,jiaotongjibenkaozou,henbufangbian。 zheigeshizhangzhidaolezheigeqingkuang,weiletishiminzhexiang,juedingxiujiangaotie。meixiujianyimihuafei1meiyuan。 xianzaishizhangqinglezuizhumingdegongchengshilaixiujiangaotie,ziranzheigegongchengshihuirangxiujiangaotiedefeiyongzuishao。 buxingdeshi,zaixiujianlegaotiezhihoujiubingshile。xianzaishizhangxiwangzhidaozaixiujianwanchengdezheixiegaotieluzhongzuizhangdeyiduangaotieluhuafeileduoshaomeiyuan, taqingnilaibangzhuta,ruguonijisuanzhengque,shizhangjianghuisongniyilianglanbojini。 shuru: diyixingyigeshut,biaoshijiexialaiyouduoshaozushuju。 jiexialaimeizuceshishujudediyixingyouyigeshun(3<=n<=500), biaoshicunzhuangshumu。 ranhoushiyigeerweishuzu,di ixingdijliebiaoshidiigecunzhuangdaodijgecunzhuangdejuli。 shuchu: zhiyouyigeshu,shuchushizhangxiwangzhidaodeyijingxiuchengdegaotiezhongzui zhangdeluhualeduoshaoqian。

daima:

#include <stdio.h> #define min(a,b) a<b?a:b #define max(a,b) a>b?a:b int map[505][505]; int vis[505],s[505];// vis表示该点到每个顶点的最小值,s标记顶点 int inf=999999; int main() { int t,n; scanf("%d",&t); while(t--) { int i,j; int res[505],ans; scanf("%d",&n); for(i=1;i<=n;i++){ vis[i]=inf; s[i]=0;// } vis[1]=0; for(i=1;i<=n;i++){ for(j=1;j<=n;j++){ scanf("%d",&map[i][j]); } } int f=1; for(int k=1;k<=n;k++){ int v=0; for(i=1;i<=n;i++){ if(!s[i] && (v==0||vis[i]<vis[v])) v=i; } if(i==0) break; s[v]=1;//标记 res[f++]=vis[v]; // res+=vis[v]; for(j=1;j<=n;j++){//松弛操作 if(!s[i]) vis[j]=min(vis[j],map[v][j]); } } for(i=2;i<=n;i++){ ans=max(res[i-1],res[i]); } printf("%d\n",ans); } return 0; }

优质网站模板

  • 1
  • 2
  • 3