HDU - 5721 Palace

【nvidia-B200】实际生产报错NVRM: nvAssertFailedNoLog: Assertion failed: pIOVAS != NULL @ io_vaspace.c:601 升级 NVIDIA 驱动到 R545/R550 数据中心版本(解决 IOVA bug,这是性能差的根本原因);重启服务器(清理驱动残留资源,消除日志中的 NVRM 错误);验证 NVLink/PCIe 链路(确保 8 卡互联使用高速链路,而非单卡 PCIe 共享带宽)。完成这 3 步后,ncccl-test的all_reduce带宽应能提升至100GB/s 以上(取决于服务器的 NVLink/NVSwitch 配置),恢复正常性能。 阅读详情

The last trial Venus imposes on Psyche is a quest to the underworld. She is to take a box and obtain in it a dose of the beauty of Prosperina, queen of the underworld. 

There are nn palaces in the underworld, which can be located on a 2-Dimension plane with (x,y)(x,y) coordinates (where x,yx,y are integers). Psyche would like to find the distance of the closest pair of two palaces. It is the password to enter the main palace. 

However, the underworld is mysterious and changes all the time. At different times, exactly one of the nn palaces disappears. 

Psyche wonders what the distance of the closest pair of two palaces is after some palace has disappeared. 

Print the sum of the distance after every single palace has disappeared. 

To avoid floating point error, define the distance dd between palace (x1,y1)(x1,y1) and (x2,y2)(x2,y2) as d=(x1−x2)2+(y1−y2)2d=(x1−x2)2+(y1−y2)2.

 

Input

The first line of the input contains an integer TT (1≤T≤5)(1≤T≤5), which denotes the number of testcases. 

For each testcase, the first line contains an integers nn (3≤n≤105)(3≤n≤105), which denotes the number of temples in this testcase. 

The following nn lines contains nn pairs of integers, the ii-th pair (x,y)(x,y) (−105≤x,y≤105)(−105≤x,y≤105) denotes the position of the ii-th palace.

 

Output

For each testcase, print an integer which denotes the sum of the distance after every single palace has disappeared.

 

Sample Input

1
3
0 0
1 1
2 2

 

Sample Output

12

 

Hint

If palace $ (0,0) $ disappears,$ d = (1-2) ^ 2 + (1 - 2) ^ 2 = 2 $;

If palace $ (1,1) $ disappears,$ d = (0-2) ^ 2 + (0 - 2) ^ 2 = 8 $;

If palace $ (2,2) $ disappears,$ d = (0-1) ^ 2 + (0-1) ^ 2 = 2 $;

Thus the answer is $ 2 + 8 + 2 = 12 $。

 题目大意:给个n个点,每次删除一个点后求最小点对的距离的平方和dist,最后输出所有的dist总和

解题思路:平面分治最小点对的模板题,n个中距离最小的两个点会被计算n-2次,因为删除除这两点之外的其他点,最小点距还是这两个点,所以只需在计算当删除的是这两个点中的其中一个点时剩余点的最小点距

平面分治最小点对:https://mp.youkuaiyun.com/postedit/85268256

AC代码:

#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
using namespace std;
typedef long long ll;
const int maxn=1e6;
const ll INF=1e18;
int X,Y;//最小两个点的下标 
ll dis; //当前最小距离 
struct node{
	ll x,y;
	int id;
}a[maxn],term[maxn];
bool cmpx(node a,node b)
{
	return a.x<b.x;
}
bool cmpy(node a,node b)
{
	return a.y<b.y;
}
ll dist(node a,node b)
{
	return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
}
void minpairs(int left,int right,int opt)//opt表示删除点的序号 
{
	if(left==right)
		return ;
	if(left+1==right)
	{
		if(a[left].id!=opt&&a[right].id!=opt)
		{
			if(dist(a[left],a[right])<dis)
			{
				dis=dist(a[left],a[right]);
				if(opt==-1)
				{
					X=a[left].id;
					Y=a[right].id; 
				}
			}
		}
		return ;
	}
	int mid=(left+right)/2;
	minpairs(left,mid,opt);
	minpairs(mid+1,right,opt);
	int i,j,k=0;
	for(i=left;i<=right;i++)
	{
		if(a[i].id!=opt&&abs(a[i].x-a[mid].x)<=dis)
			term[k++]=a[i];
	}
	sort(term,term+k,cmpy);
	for(i=0;i<k;i++)
	{
		for(j=i+1;j<k;j++)
		{
			if(term[j].y-term[i].y>dis)
				break;
			if(dist(term[j],term[i])<dis)
			{
				dis=dist(term[j],term[i]);
				if(opt==-1)
				{
					X=term[i].id;
					Y=term[j].id;
				}
			}
		}
	}
	return ;
}
int main()
{
	int t,n;
	scanf("%d",&t);
	while(t--)
	{
		ll ans=0;
		scanf("%d",&n);
		for(int i=0;i<n;i++)
		{
			scanf("%lld%lld",&a[i].x,&a[i].y);
			a[i].id=i;
		}
		dis=INF;
		sort(a,a+n,cmpx);
		minpairs(0,n-1,-1);
		ans+=dis*(n-2);
		dis=INF;
		minpairs(0,n-1,X);
		ans+=dis;
		dis=INF;
		minpairs(0,n-1,Y);
		ans+=dis;
		printf("%lld\n",ans);
	}
	return 0;
}

 

核心面试聚焦:业务问题+系统问题+设计题---字节、阿里、美团等整理统计 业务系统及其他相关面试问题整理:线上相关问题排查+高并发系统的限流+高并发秒杀系统设计+负载均衡+一个网站有 20 亿 url 存在一个黑名单中,这个黑名单要怎么存?若此时随便输入一个 url,你如何快速判断该 url 是否在这个黑名单中?并且需在给定内存空间(比如:500M)内快速判断出? 阅读详情

相关推荐

Windows下Python安装geopandas全攻略:解决GDAL依赖问题的5个关键步骤

本文详细解析了在Windows系统下安装Python地理空间分析库geopandas时,如何有效解决其核心依赖GDAL的编译难题。文章提供了五个关键步骤,包括理解依赖关系、获取预编译wheel文件、顺序安装及环境验证,旨在帮助用户绕过复杂的C++编译环境,顺利完成geopandas的安装部署。

weixin_28221501的博客 284

HDU - 5721 Palace(最近点对)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5721 分析:很显然,先对全部的点搜一遍,这个值能用n-2次,记录下最近的两个点,再搜两次,每次删除其中一个点。思路很容易想到的,主要是怎么操作。 #include<cstdio> #include<algorithm> using namespace std; typedef long long ll; const ll INF = 1e12; const int maxn = 1e5

TK_wang_的博客 191

SAP PP CSAP_MAT_BOM_MAINTAIN ECN 增加组件

SAP PP CSAP_MAT_BOM_MAINTAIN ECN 增加组件。

GAVIN 408

HDU5721(Palace)

题目传送门 Problem Description The last trial Venus imposes on Psyche is a quest to the underworld. She is to take a box and obtain in it a dose of the beauty of Prosperina, queen of the underworld. There are n palaces in the underworld, which can be located on

weixin_43808717的博客 191

MPU6050芯片 寄存器详解与配置指南(详解)

分频值越小,数据刷新越快(如分频值 = 0 时,刷新率 = 8kHz/1=8kHz)。功能:配置采样频率分频系数,控制 ADC 转换速度和数据刷新率。数据刷新率 = 陀螺仪输出时钟频率 /(1 + 分频值)

m0_74696257的博客 1420

从扇束到平行束:等角重排算法在CT重建中的核心原理与MATLAB实践

本文深入解析了CT图像重建中等角扇束重排算法的核心原理与MATLAB实现。通过将实际采集的扇束投影数据,利用几何映射和两次关键插值,转换为适用于经典滤波反投影算法的平行束数据,打通了高效重建的关键路径。文章结合Shepp-Logan模型仿真,提供了完整的MATLAB代码实践,并分析了源-物距、采样率等关键参数对重建质量的影响。

cnn8visionary的博客 647

最近点对 HDU5721

最近点对: 对所有点按照 x坐标排序。然后分治,求出左半边和右半边的最近点对,对于两边的最近距离取较小的,记为 d。取从分治的中间点向左右各距离为 d d的范围中的所有点,把这些点按照 y坐标排序。对于每个点,扫一下与它 y坐标差小于等于 d的点,更新答案,可以证明(证明没看懂=_=)这样的点是很少的,不超过6个。该题题意:给定n个点的坐标,第i个点消失后的最近点对距离为di,求di的和。这

turtlew的博客 355

AMBA-CHI协议详解(十五)

Write transactions事务描述以及请求属性,cache line状态转换。

Crazzy_M的博客 650

HDU 5721Palace

Palace Accepts: 28 Submissions: 307 Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others) 问题描述 为了寻找失去的爱人Cupid,Psyche需要完成Venus的最后一项任务:前往冥界,收集一盒冥界皇后Prospe...

weixin_30569001的博客 153

Debezium报错处理系列之二十八: Expiring 1 record(s) for test-ts-0:120001 ms has passed since batch creation

Debezium报错处理系列之二十八: Expiring 1 record(s) for test-ts-0:120001 ms has passed since batch creation

zhengzaifeidelushang的博客 3290

置顶必读(1) |《滚雪球学SpringBoot 3.x》· 高质量专栏介绍,你值得拥有!

《滚雪球学SpringBoot 3.x》 并不是普通的技术讲解合集,它是专为开发者精心设计的系统化学习路径。通过不断“滚动学习”,我们将带领你从基础入门到高阶应用,从理解每一行代码到设计和优化大规模分布式系统,最终帮助你成长为一位精通 spring架构 的工程师。

**My Coding Family** 12万+

【HDU 5721】Palace(平面最近点对)

【HDU 5721】Palace(平面最近点对) Palace Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 404    Accepted Submission(s): 104 Problem Desc

ACMer' 3134

基于3D相机的人体穴位识别与标注系统——完整Python实现方案

摘要 本文提出了一种基于3D相机的人体穴位识别与标注系统完整实现方案。系统采用Intel RealSense D435相机实时采集RGB-D数据,结合MediaPipe Pose模型进行人体33个关键骨骼点的三维姿态估计。通过建立穴位与骨骼关键点的映射关系,利用相机内参和深度信息将二维图像坐标转换为三维空间坐标。系统采用模块化设计,包含数据采集层、算法处理层、坐标转换层和可视化层,实现了穴位定位、三维坐标转换和点云可视化功能。关键技术包括:基于骨度折量法的穴位映射算法、深度图像到三维点云的转换方法,以及Op

AI的内部世界的博客 269

hdu5721Palace

链接:http://acm.hdu.edu.cn/showproblem.php?pid=5721 题意:给定n个点,设f[i]表示删掉第i个点的最近点对的距离,求sigma(1 分析:稍微想一下就知道n个点的最近点对的距离会被计算n-2次(不是删除这对点的情况),然后只要在计算两次删这对点中的点的情况就好了。PS:知道这是经典的分治求最近点对问题(不会的就自己去查资料学吧,挺简单的),比赛的

Fsss 835

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

HDU 5721 Palace

Problem Description The last trial Venus imposes on Psyche is a quest to the underworld. She is to take a box and obtain in it a dose of the beauty of Prosperina, queen of the underworld. There

Occult 603

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

HDU 5721 Palace 平面最近点对

问题描述 为了寻找失去的爱人Cupid,Psyche需要完成Venus的最后一项任务:前往冥界,收集一盒冥界皇后Prosperina的美貌。 冥界有nn个神殿,可以表示为平面上的nn个整点。Psyche想要找到这nn座神殿中,最近的两座神殿之间的距离。传说那就是通往主殿的密码。 但是冥界神秘莫测,在不同的时刻,这nn座神殿中的某一座会消失。 Psyche想要知道,对于nn座神殿中的任意一座

I good vegetable a! 510

hdu-5721 Palace(最近点对)

题目链接: Palace Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others) Problem Description The last trial Venus imposes on Psyche is a quest to the underworld. She is...

weixin_30530939的博客 158

HDU 5721 Palace(平面最近点对(分治))

http://acm.hdu.edu.cn/showproblem.php?pid=5721 n个点,去掉一个点的情况下,最近距离平方之和。平面最近点对模版题,先求出最近距离,然后找到是哪两个点,然后这个距离乘以n-2 ,然后枚举去掉两个点中的一个,再求平面最近距离,做3次即可,用stl很方便QAQ,记录是哪两个点的时候直接记录坐标,因为中间有排序,记录编号没用。代码:#include <map>

Miracle_ma的专栏 766

HDU-5721 Palace(最接近点问题 分治)

原题链接 Palace Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 551    Accepted Submission(s): 186 Problem Description The last

L. 418

HDU 5721 Palace BestCoder 2nd Anniversary (平面最近点对)

Palace Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 465    Accepted Submission(s): 118 Problem Description The last trial Venus impo

LzyRapX 1110

【HDU5721 BestCoder 2nd AnniversaryD】【平面最近点对 分治写法+KD-tree写法】Palace 平面最近点对

Palace Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 260    Accepted Submission(s): 72 Problem Description The last trial Venus imp

snowy_smile的博客 3010

BestCoder 2nd Anniversary D hdu 5721 最近点对

链接:戳这里 Palace  Time Limit: 8000/4000 MS (Java/Others)   Memory Limit: 262144/262144 K (Java/Others) 问题描述 为了寻找失去的爱人Cupid,Psyche需要完成Venus的最后一项任务:前往冥界,收集一盒冥界皇后Prosperina的美貌。 冥界有 n个神殿,可以表示为

Cross 479

分治法求最小点对(hdu1007)

先说下题意,很简单,给n个点的坐标,求距离最近的一对点之间距离的一半。第一行是一个数n表示有n个点,接下来n行是n个点的x坐标和y坐标。实数。 这个题目其实就是求最近点对的距离。《算法导论》上有详细讲解,王晓东的书上也有代码。主要思想就是分治。先把n个点按x坐标排序,然后求左边n

___简言 1万+

HDU 5128 The E-pang Palace (暴力+几何思维 详解)

E-pang Palace was built in Qin dynasty by Emperor Qin Shihuang in Xianyang, Shanxi Province. It was the largest palace ever built by human. It was so large and so magnificent that after many years of

protecteyesight的博客 899

hdu 5721 空间点对距离,记录点

#include using namespace std; typedef long long ll; const ll INF=0x3f3f3f3f3f3f3f3f; int flag; struct node1 { ll x,y; int id; }node[100010],node2[100010]; int cmpx(node1 p1,node1 p2) { if

nucshiyilang的博客 354

寻找距离最小的平面点对——分治方法

在应用中,常用诸如点、圆等简单的几何对象代表现实世界中的实体。在涉及这些几何对象的问题中,常需要了解其邻域中其他几何对象的信息。例如,在空中交通控制问题中,若将飞机作为空间中移动的一个点来看待,则具有最大碰撞危险的2架飞机,就是这个空间中最接近的一对点。这类问题是计算几何学中研究的基本问题之一。下面我们着重考虑平面上的最接近点对问题。 最接近点对问题的提法是:给定平面上n个点,找其中的一...

hpu风之旅 6170
上一篇: POJ - 3714 Raid (平面分治最小点对)
下一篇: HDU - 1007 Quoit Design
风之旅@
博客等级 码龄9年 26粉丝 255原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值