Constructing Roads --hdoj
Constructing Roads
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 32 Accepted Submission(s) : 17
or there exists a village C such that there is a road between A and C, and C and B are connected.
We know that there are already some roads between some villages and your job is the build some roads such that all the villages are connect and the length of all the roads built is minimum.
[1, 1000]) between village i and village j. Then there is an integer Q (0 <= Q <= N * (N + 1) / 2). Then come Q lines, each line contains two integers a and b (1 <= a < b <= N), which means the road between village a and village b has been built.
3
0 990 692
990 0 179
692 179 0
1
1 2
题解:第一个数字表示接下来有几行,每行有多少个数字,第一行:第一个地点与各个地点间的距离(包括自身),以此类推,N行结束之后,又有一个数字,表示接下来有M行,1 2表示1 2之间已经有路,所以不需要再建,最后求最短长度。
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
const int N = 101;
int map[N][N];
int mark[N];
int n,q,i,j;
int Prim()
{
int sum = 0;
int t = n;
int min,k;
memset(mark,0,sizeof(mark));
while(--t)
{
min = 10000;
for (i = 2; i <= n; i++)
{
if(mark[i]!=1 && map[1][i] < min)
{
min = map[1][i];
k = i;
}
}
mark[k] = 1;
sum += min;
for (j = 2; j <= n; j++)
{
if(mark[j]!=1 && map[k][j] < map[1][j])
{
map[1][j] = map[k][j];
}
}
}
return sum;
}
int main()
{
while(scanf("%d",&n)!=EOF)
{
for (i = 1; i <= n; i++)
{
for (j = 1; j <= n; j++)
{
scanf("%d",&map[i][j]);
}
}
scanf("%d",&q);
while(q--)
{
scanf("%d%d",&i,&j);
map[i][j] = 0;
map[j][i] = 0;
}
printf("%d\n",Prim());
}
return 0;
}
Constructing Roads --hdoj的更多相关文章
- HDOJ(HDU).1025 Constructing Roads In JGShining's Kingdom (DP)
HDOJ(HDU).1025 Constructing Roads In JGShining's Kingdom (DP) 点我挑战题目 题目分析 题目大意就是给出两两配对的poor city和ric ...
- Constructing Roads——F
F. Constructing Roads There are N villages, which are numbered from 1 to N, and you should build som ...
- Constructing Roads In JGShining's Kingdom(HDU1025)(LCS序列的变行)
Constructing Roads In JGShining's Kingdom HDU1025 题目主要理解要用LCS进行求解! 并且一般的求法会超时!!要用二分!!! 最后蛋疼的是输出格式的注 ...
- [ACM] hdu 1025 Constructing Roads In JGShining's Kingdom (最长递增子序列,lower_bound使用)
Constructing Roads In JGShining's Kingdom Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65 ...
- HDU 1102 Constructing Roads
Constructing Roads Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- Constructing Roads (MST)
Constructing Roads Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u ...
- HDU 1025 Constructing Roads In JGShining's Kingdom(二维LIS)
Constructing Roads In JGShining's Kingdom Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65 ...
- hdu--(1025)Constructing Roads In JGShining's Kingdom(dp/LIS+二分)
Constructing Roads In JGShining's Kingdom Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65 ...
- POJ 2421 Constructing Roads (最小生成树)
Constructing Roads Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u ...
随机推荐
- 前端-Vue结构思维导图笔记
看不清的朋友右键保存或者新窗口打开哦!喜欢我可以关注我,还有更多前端思维导图笔记有vue结构分析,JS基础,JQ,JS高级,Angular,git等等
- Windows7 win10 系统如何强制禁用驱动程序签名
转载自奇兔 Win7 64位系统禁用驱动程序签名强制 Win7系统是比较稳定的一款系统,也是最多人在使用的一款系统.当我们在Win7系统中安装驱动程序的时候,对安装的驱动程序需要数字签名,否则驱 ...
- RunLoop相关知识
RunLoop,翻译过来是运行环路.我们在创建命令行项目和创建ios项目时,发现命令行项目当最后一行代码执行完后项目就自动退出了,而ios项目确可以一直运行,知道用户手动点击退出按钮.这就是因为ios ...
- asp.net 后台注册脚本
string myScript = "function ShowPanel() { $('.nav a[href=\"#" + PanelType.wenben.ToSt ...
- DNN:逻辑回归与 SoftMax 回归方法
UFLDL Tutorial 翻译系列:http://deeplearning.stanford.edu/wiki/index.php/UFLDL_Tutorial 第四章:SoftMax回归 简介: ...
- 【sqli-labs】 less8 GET - Blind - Boolian Based - Single Quotes (基于布尔的单引号GET盲注)
加单引号 没有任何信息输出 加and 页面变化,不正常是没有任何回显 http://localhost/sqli/Less-8/?id=1' and '1'='1 http://localhost/s ...
- bootstrap 模态框日期控件datepicker被遮住问题的解决
找到日期输入框,并将 .class 属性的 z-index 改大 在JSP页添加样式: 这样就OK了:
- 查看占用某端口的进程——netstat、findstr 的使用
netstat 检验本机各端口的网络连接情况 -a 显示所有连接和侦听端口(如Windows共享服务 的135,445端口) -n 不进行IP地址到主机名的解析 -o 显示拥有的与每个连接关联的进 ...
- revit二次开发之族的类型参数与实例参数的转换
1背景小伙伴在做revit二次开发的时候,可能需要在族环境中将族的类型参数与实例参数相互转换. 2思路1.使用族管理器FamilyManager,参见注释12.首先获取需要转换的参数(单个与批量),参 ...
- 【转载】java 监听文件或者文件夹变化的几种方式
1.log4j的实现的文件内容变化监听 package com.jp.filemonitor; import org.apache.log4j.helpers.FileWatchdog; public ...