题目链接:Highways

没看题,看了输入输出。就有种似曾相识的感觉,果然和HDU1102 题相似度99%,可是也遇到一坑

cin输入居然TLE,cin的缓存不至于这么狠吧,题目非常水。矩阵已经告诉你了。就敲个模板就是了,5分钟。1A

题意就是打印,最小生成树的最大边权。改了改输入,水过

这个题完了。我的个人POJ计划进度以完毕 20/200,这当中主要是图论的题。等下周把POJ计划图论的题目打完,就回头打模拟!我就不信还能比图论难

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
const int N = 501;
const int INF = 1e8;
using namespace std;
int dis[N],mapp[N][N];
bool vis[N];
int n,ans;
void init()
{
ans = 0;
memset(vis,0,sizeof(vis));
}
void Prim()
{
int pos,minn;
for(int i = 0;i<n;i++)
dis[i] = mapp[0][i];
vis[0] = true;
for(int i = 0;i<n;i++)
{
minn = INF;
for(int j = 0;j<n;j++)
{
if(!vis[j] && dis[j] < minn)
{
minn = dis[j];
pos = j;
}
}
vis[pos] = true ; if(minn > ans && minn!=INF)
ans = minn; for(int k = 0;k<n;k++)
{
if(!vis[k] && dis[k] > mapp[pos][k])
dis[k] = mapp[pos][k];
}
}
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
init();
scanf("%d",&n);
for(int i = 0;i<n;i++)
{
for(int j = 0;j<n;j++)
scanf("%d",&mapp[i][j]);
}
Prim();
printf("%d\n",ans);
}
return 0;
}

HDU1102

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std;
const int N = 110;
const int MAX = 9999999;
int map[N][N],n;
int dis[N],vis[N];
int a,b;
int sum = 0;
int PRIM()
{
memset(dis,0,sizeof(dis));
for(int i=1;i<=n;i++)
dis[i]=map[1][i];
vis[1]=1;
int wz = 0;
for(int i=2;i<=n;i++)
{
int min= MAX; for(int j=1;j<=n;j++)
{
if(dis[j]<min&&!vis[j])
{
min=dis[j];
wz=j;
}
}
if(min<MAX)
{
vis[wz]=1;
sum+=min;
}
else
return -1;
for(int j=1;j<=n;j++)
{
if(!vis[j]&&map[wz][j]<dis[j])
dis[j]=map[wz][j];
}
}
return sum;
}
int main()
{
int q;
while (~scanf("%d",&n))
{
sum = 0;
for(int i = 1;i<=n;i++)
{
for(int j = 1;j<=n;j++)
{
scanf("%d",&map[i][j]);
}
}
memset(vis,0,sizeof(vis));
scanf("%d",&q); for(int i = 0;i<q;i++)
{
scanf("%d%d",&a,&b);
map[a][b] = 0;
map[b][a] = 0;
}
sum = PRIM();
printf("%d\n",sum);
}
return 0;
}

POJ 2485 Highways &amp;&amp; HDU1102(20/200)的更多相关文章

  1. POJ 2485 Highways (求最小生成树中最大的边)

    Description The island nation of Flatopia is perfectly flat. Unfortunately, Flatopia has no public h ...

  2. PTA 邻接表存储图的广度优先遍历(20 分)

    6-2 邻接表存储图的广度优先遍历(20 分) 试实现邻接表存储图的广度优先遍历. 函数接口定义: void BFS ( LGraph Graph, Vertex S, void (*Visit)(V ...

  3. L1-023 输出GPLT (20 分)

    L1-023 输出GPLT (20 分) 给定一个长度不超过10000的.仅由英文字母构成的字符串.请将字符重新调整顺序,按GPLTGPLT....这样的顺序输出,并忽略其它字符.当然,四种字符(不区 ...

  4. PAT 乙级 1074 宇宙无敌加法器 (20 分)

    1074 宇宙无敌加法器 (20 分) 地球人习惯使用十进制数,并且默认一个数字的每一位都是十进制的.而在 PAT 星人开挂的世界里,每个数字的每一位都是不同进制的,这种神奇的数字称为“PAT数”.每 ...

  5. PAT 乙级 1044 火星数字 (20 分)

    1044 火星数字 (20 分) 火星人是以 13 进制计数的: 地球人的 0 被火星人称为 tret. 地球人数字 1 到 12 的火星文分别为:jan, feb, mar, apr, may, j ...

  6. PAT 甲级 1035 Password (20 分)

    1035 Password (20 分) To prepare for PAT, the judge sometimes has to generate random passwords for th ...

  7. PAT 甲级 1041 Be Unique (20 分)

    1041 Be Unique (20 分) Being unique is so important to people on Mars that even their lottery is desi ...

  8. PAT 甲级 1054 The Dominant Color (20 分)

    1054 The Dominant Color (20 分) Behind the scenes in the computer's memory, color is always talked ab ...

  9. PAT 甲级 1027 Colors in Mars (20 分)

    1027 Colors in Mars (20 分) People in Mars represent the colors in their computers in a similar way a ...

随机推荐

  1. poj1787 Charlie's Change

    思路: 完全背包,记录路径. 实现: #include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; ] ...

  2. Python 将中文转拼音

    文字转拼音 import os.path class PinYin(object): def __init__(self): self.word_dict = {} def load_word(sel ...

  3. servU服务器连接不上问题的解决

    在服务器上安装了servU64位版,建立了用户,设置了防火墙,正常启动. 但在客户端发出FTP://服务器IP 命令后,弹出输入用户名和密码的对话框,输入正确的用户名和密码后,却始终连接不上. ftp ...

  4. mysql 存储引擎学习

    现在我们常用的MySQL存储引擎主要是两种:InnoDB and MyISAM. 1.MyISAM 执行效率高 不支持事务 不支持外键 每个MyISAM在磁盘上存储成3个文件,其中文件名和表名都相同, ...

  5. Laravel 网站项目目录结构规划

    最近在用Laravel这个PHP框架搭网站,大致了解这个框架的目录结构之后感觉学到了不少东西. 首先安装好包管理器: PHP部分当然用composer,安装在全局目录下方便一点. 前端部分,我没有选择 ...

  6. blog笔录1

    (1)虚拟主机 (2)部署 部署完成后刷新页面会看到笑脸,在Home分组下控制器Application/Home/Controller/IndexController.class.php下定义显示 ( ...

  7. CentOS下安装微软雅黑字体

    CentOS下安装微软雅黑字体   微软雅黑下载地址:http://download.csdn.net/detail/u012547633/9796219 1.先从你本机 C:\Windows\Fon ...

  8. ios xmpp 发送语音图片解决方案

    ios xmpp 发送语音,图片解决方案,有需要的朋友可以参考下. 目前做IM多是用的xmpp. 因为项目需求需要实现语音和图片的发送. 发送语音图片有三种方法. 1,xmpp smack.文件传输方 ...

  9. 类模板成员函数默认值问题:an out-of-line definition of a member of a class template cannot have default arguments

    template <typename T> class A { ); }; template<typename T> ) { /* */ } 对于类似上文代码,VS编译器会报 ...

  10. python3.x Day3 文件操作

    文件操作:操作文件实际是4步骤1.描述文件是哪个 2.打开文件 3.操作文件 4.关闭文件 1.打开文件使用open方法,代码举例: data=open("wait_you",en ...