Educational Codeforces Round 124 (Rated for Div. 2)
比赛链接
Educational Codeforces Round 124 (Rated for Div. 2)
D. Nearest Excluded Points
You are given distinct points on a plane. The coordinates of the -th point are .
For each point , find the nearest (in terms of Manhattan distance) point with integer coordinates that is not among the given points. If there are multiple such points - you can choose any of them.
The Manhattan distance between two points and is .
Input
The first line of the input contains one integer - the number of points in the set.
The next lines describe points. The -th of them contains two integers and coordinates of the -th point. It is guaranteed that all points in the input are distinct.
Output
Print lines. In the -th line, print the point with integer coordinates that is not among the given points and is the nearest (in terms of Manhattan distance) to the -th point from the input.
Output coordinates should be in range . It can be shown that any optimal answer meets these constraints.
If there are several answers, you can print any of them.
Examples
input
output
input
output
解题思路
bfs
先把那些哈密顿距离为 ,即距离家最近且点集中不存在的点找出来的,则剩余的那些点一定在这些点的附近,否则也能找到不能存在点集且两点间的哈密顿距离为 的点,将之前那些已经找到答案的点每次向外扩张,即多源 ,找跟其距离最近且没有答案的点,找到最短的那个点,源点的答案即为找到的那个点的答案,因为其哈密顿距离最小为最短路加一
- 时间复杂度:
代码
__EOF__

本文链接:https://www.cnblogs.com/zyyun/p/15995380.html
关于博主:评论和私信会在第一时间回复。或者直接私信我。
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角【推荐】一下。您的鼓励是博主的最大动力!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!