POJ 1751 Highways

Halcon图片拼接避坑指南:特征点匹配常见问题与解决方案 本文深入解析Halcon图片拼接中特征点匹配的常见问题与解决方案,涵盖特征点提取、匹配优化及变换模型选择等关键环节。针对工业视觉检测中的拼接错位、重影等问题,提供参数调优、图像预处理和算法选择等实战技巧,帮助开发者高效避坑并提升拼接精度。 阅读详情

Highways
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 9681 Accepted: 2731 Special Judge

Description

The island nation of Flatopia is perfectly flat. Unfortunately, Flatopia has a very poor system of public highways. The Flatopian government is aware of this problem and has already constructed a number of highways connecting some of the most important towns. However, there are still some towns that you can't reach via a highway. It is necessary to build more 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 and town i has a position given by the Cartesian coordinates (xi, yi). Each highway connects exaclty two towns. All highways (both the original ones and the ones that are to be built) follow straight lines, and thus their length is equal to Cartesian distance between towns. 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 cost of building new highways. However, they want to guarantee that every town is highway-reachable from every other town. Since Flatopia is so flat, the cost of a highway is always proportional to its length. Thus, the least expensive highway system will be the one that minimizes the total highways length. 

Input

The input consists of two parts. The first part describes all towns in the country, and the second part describes all of the highways that have already been built. 

The first line of the input file contains a single integer N (1 <= N <= 750), representing the number of towns. The next N lines each contain two integers, xi and yi separated by a space. These values give the coordinates of ith town (for i from 1 to N). Coordinates will have an absolute value no greater than 10000. Every town has a unique location. 

The next line contains a single integer M (0 <= M <= 1000), representing the number of existing highways. The next M lines each contain a pair of integers separated by a space. These two integers give a pair of town numbers which are already connected by a highway. Each pair of towns is connected by at most one highway. 

Output

Write to the output a single line for each new highway that should be built in order to connect all towns with minimal possible total length of new highways. Each highway should be presented by printing town numbers that this highway connects, separated by a space. 

If no new highways need to be built (all towns are already connected), then the output file should be created but it should be empty. 

Sample Input

9
1 5
0 0 
3 2
4 5
5 1
0 4
5 2
1 2
5 3
3
1 3
9 7
1 2

Sample Output

1 6
3 7
4 9
5 7
8 3


题目链接:http://poj.org/problem?id=1751


题目大意:有n座城市,用1-n标记,给出每座城市的坐标,然后输入已有的路的数目和每条路的起点、终点城市。求要使每座城市连通,还需要建的路,保证每一条路长度最小。


解题思路:用到并查集和克鲁斯卡尔算法,先构造每座城市间的距离,一共有n(n-1)/2条路,用结构体存储起始城市和城市间的距离,按距离从小到大排序,已有通路的城市按通路从小到大合并。没有和并的城市合并,并输出起始城市,当路径数目为n-1时结束。


代码如下:

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn=755;
int fa[755];
int xx[755],yy[755];
struct A
{
    int x,y;
	int w;
}eg[maxn*maxn/2];
int find(int x)
{
    return x==fa[x]?x:fa[x]=find(fa[x]);
}
void Union(int a,int b)
{
    int a1=find(a);
    int b1=find(b);
    if(a1!=b1)
		fa[a1]=b1;
}
int cmp(A a,A b)
{
    return a.w<b.w;
}
int main()
{
    int n,m,a,b,j,i;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        fa[i]=i;
        scanf("%d%d",&xx[i],&yy[i]);
    }
	int cnt=0;
	for(i=1;i<n;i++)
		for(j=i+1;j<=n;j++)
		{
			eg[++cnt].x=i;
			eg[cnt].y=j;
			eg[cnt].w = ((xx[i]-xx[j])*(xx[i]-xx[j])+(yy[i]-yy[j])*(yy[i]-yy[j]));
		}
    sort(eg+1,eg+cnt+1,cmp);
    scanf("%d",&m);
	cnt=0;
    for(i=0;i<m;i++)
    {
        scanf("%d%d",&a,&b);
		if(find(a)!=find(b))
		{
			Union(a,b);
			cnt++;
		}
    }
    for(i=1;i<maxn*maxn/2;i++)
    {
        if(find(eg[i].x)!=find(eg[i].y))
        {
			cnt++;
            Union(eg[i].x,eg[i].y);
            printf("%d %d\n",eg[i].x,eg[i].y);
        }
		if(cnt==n-1)break;
    }
    return 0;
}


OpenCV-Python实战(10)——详解 OpenCV 轮廓检测 在计算机视觉领域,轮廓通常指图像中对象边界的一系列点。因此,轮廓通常描述了对象边界的关键信息,包含了有关对象形状的主要信息,该信息可用于形状分析与对象检测和识别。在本文中,将首次通过简单示例了解轮廓的基本概念,然后通过实际示例来了解如何检测和压缩轮廓,最后利用介绍如何利用图像矩描述检测到的轮廓属性。 阅读详情

相关推荐

保姆级教程:STK 11.0 从下载到安装成功(附Matlab互联配置与常见问题解决)

本文提供STK 11.0的完整安装指南,包括下载、安装步骤、Matlab互联配置及常见问题解决方案。详细介绍了系统要求核查、分步安装流程、关键文件替换和许可证配置,确保用户能够顺利完成STK 11.0的部署并实现与Matlab的无缝对接。

weixin_30698297的博客 349

poj-1751 Highways

http://poj.org/problem?id=1751 最小生成树简单应用 #include #include #include #include #include #include #include using namespace std; #define INF 10000000 double map[1110][1110],dis[1110]; int n,m,v

mfcheer 745

Hodgkin-Huxley Model

介绍了经典的动力学模型:HH Model

weixin_73557167的博客 2484

POJ 1751 Highways(Kruskal Algorithm)

题目链接: POJ 1751 Highways 题意: 有n个点需要修公路将这n个点连通,修公路里程越长,成本越高。已知有m条公路已经修好了的。 求出最少成本下,需要修哪些公路,将这些公路的起始点输出来。 分析: 最小生成树。将m条已经修好的公路用并查集合并下,再用Kruskal算法记录下修的公路起始点即可。 注意: 测试样例无需循环读入,直接scanf(“%d”,&n);即可,用w

ramay7 500

保姆级教程:在PyCharm里用Continue插件一键接入DeepSeek API(含乱码修复)

本文详细介绍了如何在PyCharm中通过Continue插件无缝集成DeepSeek API,提供从环境准备到高级配置的全流程指南,包括解决常见的乱码问题。通过本教程,开发者可以轻松实现AI编程助手的高效调用,提升代码编写和调试效率。

weixin_30275415的博客 852

数据可视化—power bi 基础操作汇总

数据来源: https://pan.baidu.com/s/1U_Y7rKfhnSKbLmh4FcUD_Q 提取码: yq5v 目录 基本功能与视图 编辑与查询—修改column案例 建立关联性 新增column与DAX完成总价运算 习题练习1:建立可视化图表 产品销售统计图 column拖曳可视化 1.基本功能与视图 ①基础操作界面 ②获取数据—以打开excel为例 ③数据文件基本视图 可视化形式:柱状图、数据、关联性 2.编辑与查询—修改column ①编辑与查询—数据处理界面 .

weixin_52730784的博客 2691

POJ 1751 Highways

Highways Description The island nation of Flatopia is perfectly flat. Unfortunately, Flatopia has a very poor system of public highways. The Flatopian government is aware of this problem and has alrea...

旺崽的博客 3095

不止是打字机效果:手把手教你用SpannableStringBuilder打造Android富文本AI对话界面

本文详细介绍了如何使用SpannableStringBuilder在Android平台上构建专业级AI对话界面,涵盖流式文本处理、富文本解析、交互优化等核心技术。通过实战代码示例,帮助开发者实现类似DeepSeek的AI产品交互效果,提升用户体验和应用专业度。

weixin_28358083的博客 204

POJ 1751 Highways 最小生成树

POJ 1751 Highways 最小生成树  题意:给你n个村庄的坐标,然后再给你m行,每行的两个数字代表公路两端的村庄编号(1~n),问在花费最少的情况下还需建哪些路才能使所有村庄连通。  思路:kruskal的话思路很明确,先建好边集,然后将每条已经建好的路执行合并操作,即Add(a,b);,然后再用kruskal输出一遍每次建边的两个村庄编号就OK。prim的话,没想到该怎么写,网上很多题

LucienShui 576

FLUENT Meshing Watertight Geometry工作流入门 - 4 局部加密区域

总结一下本课程中学到的内容:我们了解了如何使用模型中特定兴趣区域的BOI和FOI局部尺寸控制来加密网格。然后,了解了如何使用Box类型的局部细化区域。最后,学习了Ansys Fluent Meshing Watertight Geometry Workflow的Offset Surface类型创建局部细化区域任务。

B_etter_Man的博客 6672

PyTorch深度学习项目实战100例数据集

最近很多订阅了的用户私信咨询有些数据集下载不了以及一些文章中没有给出数据集链接,为了解决这个问题,专门开设了本篇文章,提供数据集下载链接,打包100例的所有数据集。本专栏适用人群:深度学习初学者,专栏将具体讲解如何快速搭建深度学习模型用自己的数据集实现深度学习小项目。 本专栏整理了《PyTorch深度学习项目实战100例》,内包含了各种不同的深度学习项目,包含项目原理以及源码,每一个项目实例都附带有完整的代码+数据集。

CSDN 精品推荐 2万+

【最小生成树专题】POJ 1751 Highways

 POJ 1751 Highways Highways 题目链接-&gt;http://poj.org/problem?id=1751 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 18416   Accepted: 5415   Special Judge Descrip...

荷叶田田 413

扩散模型中的UNET

一、为什么UNET模型可以用于去噪网络 二、扩散模型中的UNET是一个条件去噪网络,怎么实现的 三、UNET用于分割和用去去噪的区别

m0_37737957的博客 3822

POJ1751-Highways

问题链接:【1751】(http://poj.org/problem?id=1751) Description The island nation of Flatopia is perfectly flat. Unfortunately, Flatopia has a very poor system of public highways. The Flatopian government is a

远方水木 528

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

POJ-1751 Highways

Highways Time Limit: 1000MS   Memory Limit: 10000K     Special Judge Description The island nation of Flatopia is perfectly flat. Unfortunately, Flatopia has a very poo

JSure的代码库 1055

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

poj1751 Highways

题目链接:http://poj.org/problem?id=1751 题意:给你一个n个点,点之间的边权为两点间距离,而且有m条边的距离为0,现在让你求这个图的最小生成树,且输出最小生成树上边权不为0的边 解析:做最小生成树的时候直接把边存起来即可,最后输出一下#include <iostream> #include <algorithm> #include <cstdio> #include

22h's Blog 551

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

poj1751——Highways

<br />题意:给定N个城市的坐标,然后下面给出M个已经连接好的城市标号,求他们之间的最小生成树,其中,已连接的话,不必输出。<br />思路:将已给的城市之间距离标为0,输出的时候,城市之间为零的就不必输出。<br />#include<iostream> #include<cstdio> #include<cstring> #include<math.h> using namespace std; class tt { public: int x,y; }town[760]; i

r_ax的专栏 1387

POJ 1751Highways

1 #include<cstdio> 2 #include<cmath> 3 #include<iostream> 4 using namespace std; 5 #define INF 1<<29 6 int n,m,A,B; 7 int x[760],y[760],visit[760],pat...

136

POJ1751(Highways)

算法:最小生成树 POJ真是坑爹啊,还搞出了个Special Judge,说白了就是输出可以与样例不同,害的我在这找了半天错。 本题也没什么难度,就是记录一下路径,把那些必连边的权值赋0,同时给这些边做上标记。 在找点的时候记录每个点的父节点,也就是它们是被谁更新的,这样再

250

Poj 1751 Highways

Poj 1751 Highways 题目链接 Highways Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 21476 Accepted: 6337 Special Judge Description The island nation of Flatopia is perfectly fla...

qq_37804582的博客 167

POJ 1751 Highways Kruskal求解

题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=66965#problem/H 题意:修高速公路问题,求最小连通造价,但是会给出一些已经修好了的边,求需要修剪的边。 思路:这题和POJ 2412 Constructing Roads差不多,用Kruskal逐条加边,只是把Kruskal的求sum值改成存储边值就好了。

catch_catch的专栏 698

Highways POJ - 1751

题目链接:https://cn.vjudge.net/problem/POJ-1751 题目:给出n个点的坐标,然后,有m条路已经修好,问把所有点都联系起来,最小的花费是多少。 分析:最小生成树。。。先把已经修好的连起来,再用最小生成树求就可以了。 #include<iostream> #include<cstdio> #include<string.h&gt...

黄油^小饼干的博客 185

POJ1751 Highways

Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%lld & %llu Description The island nation of Flatopia is perfectly flat. Unfortunately, Flatopia has...

dezhen7015的博客 127

【POJ 1751 --- Highways】prim

【POJ 1751 --- Highways】prim 题目来源:点击进入【POJ 1751 — Highways】 Description The island nation of Flatopia is perfectly flat. Unfortunately, Flatopia has a very poor system of public highways. The Flatopian...

来日浅谈的博客 494
上一篇: poj 3624 Charm Bracelet
下一篇: POJ 2502 Subway(迪杰斯特拉)
雨狮子
博客等级 码龄12年 24粉丝 185原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址