POJ 2485 Highways && HDU1102(20/200)
题目链接: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 && HDU1102(20/200)的更多相关文章
- POJ 2485 Highways (求最小生成树中最大的边)
Description The island nation of Flatopia is perfectly flat. Unfortunately, Flatopia has no public h ...
- PTA 邻接表存储图的广度优先遍历(20 分)
6-2 邻接表存储图的广度优先遍历(20 分) 试实现邻接表存储图的广度优先遍历. 函数接口定义: void BFS ( LGraph Graph, Vertex S, void (*Visit)(V ...
- L1-023 输出GPLT (20 分)
L1-023 输出GPLT (20 分) 给定一个长度不超过10000的.仅由英文字母构成的字符串.请将字符重新调整顺序,按GPLTGPLT....这样的顺序输出,并忽略其它字符.当然,四种字符(不区 ...
- PAT 乙级 1074 宇宙无敌加法器 (20 分)
1074 宇宙无敌加法器 (20 分) 地球人习惯使用十进制数,并且默认一个数字的每一位都是十进制的.而在 PAT 星人开挂的世界里,每个数字的每一位都是不同进制的,这种神奇的数字称为“PAT数”.每 ...
- PAT 乙级 1044 火星数字 (20 分)
1044 火星数字 (20 分) 火星人是以 13 进制计数的: 地球人的 0 被火星人称为 tret. 地球人数字 1 到 12 的火星文分别为:jan, feb, mar, apr, may, j ...
- PAT 甲级 1035 Password (20 分)
1035 Password (20 分) To prepare for PAT, the judge sometimes has to generate random passwords for th ...
- PAT 甲级 1041 Be Unique (20 分)
1041 Be Unique (20 分) Being unique is so important to people on Mars that even their lottery is desi ...
- PAT 甲级 1054 The Dominant Color (20 分)
1054 The Dominant Color (20 分) Behind the scenes in the computer's memory, color is always talked ab ...
- 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 ...
随机推荐
- [ CodeForces 1064 B ] Equations of Mathematical Magic
\(\\\) \(Description\) \(T\) 组询问,每次给出一个 \(a\),求方程 \[ a-(a\oplus x)-x=0 \] 的方案数. \(T\le 10^3,a\le 2^{ ...
- 【ZT】在微信上有哪些高情商的说话方式 | M周刊(听语音需要60秒,看文字只需10秒)
https://baijiahao.baidu.com/s?id=1590547145580792217&wfr=spider&for=pc https://yuedu.baidu.c ...
- mybatis 关联查询
1.关联的两个实体类 外部类 parent public class Parent{ private String parentId; private String parentName; priva ...
- postgresql遇到的性能问题
问题SQL scwksmlcls.wk_cls_c , scwklrgcls.wk_lrg_cls_nm , scwkmdlcls.wk_mdl_cls_nm , scwksmlcls.wk_sml_ ...
- Linux系统调用--getrusage函数详解
Linux系统调用--getrusage函数详解 功能描述: 获得进程的相关资源信息.如:用户开销时间,系统开销时间,接收的信号量等等; 用法: #include <sys/t ...
- 分析器错误消息: 该配置节不能包含 CDATA 或文本元素。
原因当然是web.config配置文件中,有字符串文本了,估计不小心加上的一些字符,所以会报错,去掉就行,例如13行的s
- 梦想MxWeb3D协同设计平台 2019.01.24更新
SDK开发包下载地址:http://www.mxdraw.com/ndetail_10124.html1. 编写快速入门教程2. 重构前端代码,支持一个页面多个三维控件同时加载,或二维和三维同时加 ...
- 01Microsoft SQL Server
Microsoft SQL Server Microsoft SQL Server 是Microsoft 公司推出的关系型数据库管理系统.具有使用方便可伸缩性好与相关软件集成程度高等优点,可跨越膝上型 ...
- org.hibernate.AnnotationException: mappedBy reference an unknown target entity property
org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: xxxxxxx 原因是 ...
- 【2018百度之星初赛(A)】1002 度度熊学队列
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=6375 Knowledge Point: STL - map:https://www.cnblogs.c ...