- 1、本文档共10页,可阅读全部内容。
- 2、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
中南大学算法设计与分析实验报告
实验一 分治
—最近点对
问题
Problem
Have you ever played quoit in a playground? Quoit is a game in which flat rings are pitched at some toys, with all the toys encircled awarded.In the field of Cyberground, the position of each toy is fixed, and the ring is carefully designed so it can only encircle one toy at a time. On the other hand, to make the game look more attractive, the ring is designed to have the largest radius. Given a configuration of the field, you are supposed to find the radius of such a ring.Assume that all the toys are points on a plane. A point is encircled by the ring if the distance between the point and the center of the ring is strictly less than the radius of the ring. If two toys are placed at the same point, the radius of the ring is considered to be 0.
Input
The input consists of several test cases. For each case, the first line contains an integer N (2 = N = 100,000), the total number of toys in the field. Then N lines follow, each contains a pair of (x, y) which are the coordinates of a toy. The input is terminated by N = 0.
Output
For each test case, print in one line the radius of the ring required by the Cyberground manager, accurate up to 2 decimal places.
分析思路
题目是给n个点的坐标,求距离最近的一对点之间距离的一半。第一行是一个数n表示有n个点,接下来n行是n个点的x坐标和y坐标。
首先,假设点是n个,编号为1到n。找一个中间的编号mid,先求出1到mid点的最近距离设为d1,还有mid+1到n的最近距离设为d2。如果说最近点对中的两点都在1-mid集合中,或者mid+1到n集合中,则d就是最小距离了。但是还有可能的是最近点对中的两点分属这两个集合,若存在,则把这个最近点对的距离记录下来,去更新d。这样就得到最小的距离d了。
源代码
#includestdio.h
#includemath.h
#includealgorithm
using namespace std;
#define N 1000010
struct point
{
double x;
double y;
}p1[N],p2[N];
double dis ( point a , point b )
{
return sqrt( pow (a.x-b.x,2) + pow ( a.y-b.y,2 ) );
}
double min ( double a , double b )
{
return ab?a:b;
}
bool cpx ( point a , point b )
{
return a.x b.x ;
}
bool cpy ( point a , point b )
{
return a.y b.y ;
}
double mindis ( int l , int r )
{
if( l + 1 == r )
return dis ( p1[l] ,p1[r] );
if( l + 2 == r )
return min ( dis ( p1[l
您可能关注的文档
- unit5_what_were_you_doing_when_the_rainstorm_came导学案.doc
- 圣诞节是否放假 英文辩论材料.doc
- 最优化方法MATLAB4.doc
- 八年级一对一 Unit7.doc
- 如何背GRE15000词汇!单词+背法.docx
- 博森李安:易混词的终结版.doc
- 高一英语必修二U3.doc
- 2016名师测控人教版八年级英语下册(导学案)Unit5Period2.doc
- 八年级下册Unit9教案.doc
- 2016年外研社九年级英语上册Module 2 Public holidays预习与检测.doc
- 25上半年2期套题班-行政职业能力测验(八).docx
- 公考讲义-2025年1月时政汇总.pdf
- 2025年省考逻辑填空1000 高频实词积累+刷题早读课 讲义.pdf
- 25上半年2期套题班-行政职业能力测验(九).docx
- 2025四川事业编FB综合岗考试-综合能力测试讲义-主观题基础,案例分析题,公文写作及文章写作题.pdf
- 25上半年2期套题班-行政职业能力测验(五).docx
- 2025申论多省联考刷题课真题资料-2025国考执法课程.doc
- 2025申论多省联考刷题课真题资料-2024江西执法课程.doc
- 25上半年2期套题班-行政职业能力测验(十).docx
- 2025申论多省联考刷题课真题资料-2024福建县乡课程.doc
文档评论(0)