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 ...
随机推荐
- 详细解读css中的浮动以及清除浮动的方法
对于前端初学者来说,css浮动部分的知识是一块比较难以理解的部分,下面我将把我学习过程中的心得分享给大家. 导读: 1.css块级元素讲解 2.css中浮动是如何产生的 3.出现浮动后,如何清除浮 ...
- android黑科技系列——Wireshark和Fiddler分析Android中的TLS协议包数据(附带案例样本)
一.前言 在之前一篇文章已经介绍了一款网络访问软件的破解教程,当时采用的突破口是应用程序本身的一个漏洞,就是没有关闭日志信息,我们通过抓取日志获取到关键信息来找到突破口进行破解的.那篇文章也说到了,如 ...
- VMWare linux安装mysql 5.7.13
1.基础环境说明 虚拟机:VMWare 操作系统:linux 数据库版本:mysql 5.7.13 社区版(别问为什么不装企业版,因为企业版要钱) 背景:虚拟机可以连上外网 下载目录: /tools/ ...
- win2008系统日志不断出现【审核失败】
win2008系统日志不断出现[审核失败] [现象] 今天查看windows日志,在 -安全- 发现不断有消息刷出,显示 -审核失败- 事件ID为4624 的记录 每分钟大概刷新8条消息(如 ...
- Python3编写Windows服务程序
最近做了公司签到的小工具,有同事要求做成Windows服务,开机自启.先说下怎么用Python写Windows服务程序. #encoding=utf-8 import win32serviceutil ...
- Django_文件上传
使用Django框架实现文件上传功能 upload.html <!DOCTYPE html> <html lang="en"> <head> ...
- vue组件的拆分
vue组件的拆分 <div class="div"> <!-- 拆分出来的组件 自定义名字moban --> <moban></moban ...
- 算法87-----DAG有向无环图的拓扑排序
一.题目:课程排表---210 课程表上有一些课,是必须有修学分的先后顺序的,必须要求在上完某些课的情况下才能上下一门.问是否有方案修完所有的课程?如果有的话请返回其中一个符合要求的路径,否则返回[] ...
- Golang - 爬虫案例实践
目录 Golang - 爬虫案例实践 1. 爬虫步骤 2. 正则表达式 3. 并发爬取美图 Golang - 爬虫案例实践 1. 爬虫步骤 明确目标(确定在哪个网址搜索) 爬(爬下数据) 取(去掉没用 ...
- netty使用MessageToByteEncoder 自定义协议(四)
开发应用程序与应用程序之间的通信,程序之前通信 需要定义协议,比如http协议. 首先我们定义一个协议类 package com.liqiang.SimpeEcode; import java.sql ...