地址:http://poj.org/problem?id=1981

题目:

Circle and Points
Time Limit: 5000MS   Memory Limit: 30000K
Total Submissions: 8198   Accepted: 2924
Case Time Limit: 2000MS

Description

You are given N points in the xy-plane. You have a circle of radius one and move it on the xy-plane, so as to enclose as many of the points as possible. Find how many points can be simultaneously enclosed at the maximum. A point is considered enclosed by a circle when it is inside or on the circle. 
 
Fig 1. Circle and Points

Input

The input consists of a series of data sets, followed by a single line only containing a single character '0', which indicates the end of the input. Each data set begins with a line containing an integer N, which indicates the number of points in the data set. It is followed by N lines describing the coordinates of the points. Each of the N lines has two decimal fractions X and Y, describing the x- and y-coordinates of a point, respectively. They are given with five digits after the decimal point.

You may assume 1 <= N <= 300, 0.0 <= X <= 10.0, and 0.0 <= Y <= 10.0. No two points are closer than 0.0001. No two points in a data set are approximately at a distance of 2.0. More precisely, for any two points in a data set, the distance d between the two never satisfies 1.9999 <= d <= 2.0001. Finally, no three points in a data set are simultaneously very close to a single circle of radius one. More precisely, let P1, P2, and P3 be any three points in a data set, and d1, d2, and d3 the distances from an arbitrarily selected point in the xy-plane to each of them respectively. Then it never simultaneously holds that 0.9999 <= di <= 1.0001 (i = 1, 2, 3).

Output

For each data set, print a single line containing the maximum number of points in the data set that can be simultaneously enclosed by a circle of radius one. No other characters including leading and trailing spaces should be printed.

Sample Input

3
6.47634 7.69628
5.16828 4.79915
6.69533 6.20378
6
7.15296 4.08328
6.50827 2.69466
5.91219 3.86661
5.29853 4.16097
6.10838 3.46039
6.34060 2.41599
8
7.90650 4.01746
4.10998 4.18354
4.67289 4.01887
6.33885 4.28388
4.98106 3.82728
5.12379 5.16473
7.84664 4.67693
4.02776 3.87990
20
6.65128 5.47490
6.42743 6.26189
6.35864 4.61611
6.59020 4.54228
4.43967 5.70059
4.38226 5.70536
5.50755 6.18163
7.41971 6.13668
6.71936 3.04496
5.61832 4.23857
5.99424 4.29328
5.60961 4.32998
6.82242 5.79683
5.44693 3.82724
6.70906 3.65736
7.89087 5.68000
6.23300 4.59530
5.92401 4.92329
6.24168 3.81389
6.22671 3.62210
0

Sample Output

2
5
5
11

Source

思路:

  n^2logn的思路挺巧的,首先枚举每个点P,然后枚举其他点Q,算出以P为圆心和以Q为圆心的重叠部分,显然重叠部分最多的地方就是放圆心的最好位置。

  求重叠次数是通过与两圆相交的交点构成的圆弧来判断的。

 #include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm> using namespace std;
const double PI = acos(-1.0);
const double eps = 1e-; /****************常用函数***************/
//判断ta与tb的大小关系
int sgn( double ta, double tb)
{
if(fabs(ta-tb)<eps)return ;
if(ta<tb) return -;
return ;
} //点
class Point
{
public: double x, y; Point(){}
Point( double tx, double ty){ x = tx, y = ty;} }; /****************常用函数***************/ //两点间距离的平方
double getdis2(const Point &st,const Point &se)
{
return (st.x - se.x) * (st.x - se.x) + (st.y - se.y) * (st.y - se.y);
}
//两点间距离
double getdis(const Point &st,const Point &se)
{
return sqrt((st.x - se.x) * (st.x - se.x) + (st.y - se.y) * (st.y - se.y));
} Point pt[],pp[]; bool cmp(const Point &ta,const Point &tb)
{
return sgn(ta.x,tb.x)!=?ta.x<tb.x:ta.y>tb.y;
}
int main(void)
{
//freopen("in.acm","r",stdin);
int n;
while(~scanf("%d",&n)&&n)
{
int ans=;
for(int i=;i<=n;i++)
scanf("%lf%lf",&pt[i].x,&pt[i].y);
for(int i=;i<=n;i++)
{
int cnt=,tot=;;
for(int j=;j<=n;j++)
if(i!=j)
{
double d = getdis(pt[i],pt[j]) / 2.0;
if(sgn(d,)>) continue;
double ag = atan2(pt[j].y-pt[i].y,pt[j].x-pt[i].x);
d = acos(d);
pp[cnt].x = ag - d, pp[cnt++].y = ;
pp[cnt].x = ag + d, pp[cnt++].y = -;
}
sort(pp,pp+cnt,cmp);
for(int j=;j<cnt;j++)
if(pp[j].y>)
ans=max(ans,++tot);
else
tot--;
}
printf("%d\n",ans);
}
return ;
}

poj1981 Circle and Points的更多相关文章

  1. poj1981 Circle and Points 单位圆覆盖问题

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Circle and Points Time Limit: 5000MS   Me ...

  2. POJ-1981 Circle and Points 单位圆覆盖

    题目链接:http://poj.org/problem?id=1981 容易想到直接枚举两个点,然后确定一个圆来枚举,算法复杂度O(n^3). 这题还有O(n^2*lg n)的算法.将每个点扩展为单位 ...

  3. bzoj1338: Pku1981 Circle and Points单位圆覆盖

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1338 1338: Pku1981 Circle and Points单位圆覆盖 Time ...

  4. poj 1981 Circle and Points

    Circle and Points Time Limit: 5000MS   Memory Limit: 30000K Total Submissions: 8131   Accepted: 2899 ...

  5. 【POJ 1981 】Circle and Points

    当两个点距离小于直径时,由它们为弦确定的一个单位圆(虽然有两个圆,但是想一想知道只算一个就可以)来计算覆盖多少点. #include <cstdio> #include <cmath ...

  6. POJ 1981 Circle and Points (扫描线)

    [题目链接] http://poj.org/problem?id=1981 [题目大意] 给出平面上一些点,问一个半径为1的圆最多可以覆盖几个点 [题解] 我们对于每个点画半径为1的圆,那么在两圆交弧 ...

  7. 【POJ 1981】Circle and Points(已知圆上两点求圆心坐标)

    [题目链接]:http://poj.org/problem?id=1981 [题意] 给你n个点(n<=300); 然后给你一个半径R: 让你在平面上找一个半径为R的圆; 这里R=1 使得这个圆 ...

  8. POJ - 1981 :Circle and Points (圆的扫描线) hihocoder1508

    题意:给定N个点,然后给定一个半径为R的圆,问这个圆最多覆盖多少个点. 思路:在圆弧上求扫描线. 如果N比较小,不难想到N^3的算法. 一般这种覆盖问题你可以假设有两个点在圆的边界上,那么每次产生的圆 ...

  9. 【Checkio Exercise】Three Point Circle

    计算三角形外接圆的函数: Three Point Circle If we want to build new silos, then we need to make more formal and ...

随机推荐

  1. python2.0_s12_day21_web聊天室一

    本节内容: 项目实战:开发一个WEB聊天室 功能需求: 用户可以与好友一对一聊天 可以搜索.添加某人为好友 用户可以搜索和添加群 每个群有管理员可以审批用户的加群请求,群管理员可以用多个,群管理员可以 ...

  2. 批处理bat文件dos命令实现文件的解压缩

    ::========压缩文件======================= ::将源路径“C:\Users\xcc\Desktop\多大的经济 ”路径下的文件压缩到目标路径下“D:\迅雷下载\压缩.r ...

  3. 安全日志:/var/log/secure

    /var/log/secure 一般用来记录安全相关的信息,记录最多的是哪些用户登录服务器的相关日志,如果该文件很大,说明有人在破解你的 root 密码 [root@localhost ~]$ tai ...

  4. UE4读取脑电波MindWave插件(展示如何使用第三方库制作UE4插件)

    MyEEGPlugin.uplugin { , , "VersionName": "1.0", "FriendlyName": " ...

  5. 新唐ARM9之NUC972学习历程之系统的搭建和BSP包的使用

    说到嵌入式,我们首先想到的,就是它的复杂程度,LINUX,BSP,UBOOT,交叉编译,寄存器配置,等等一系列的问题,甚至有的时候我们对此一头雾水,很是头疼,不过我们今天要说的就是关于NUC972的一 ...

  6. apply的调用 http://bbs.51js.com/thread-82017-1-3.html

    applay 这个是函数Function的方法为什么Array 也能调用这个函数?比如     function a (){           var kk = [];           kk = ...

  7. JQuery事件e参数的方法preventDefault()取消默认行为

    <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...

  8. CHMOD命令怎么用?

    文件/目录权限设置命令:chmod 这是Linux系统管理员最常用到的命令之一,它用于改变文件或目录的访问权限.该命令有两种用法: 用包含字母和操作符表达式的文字设定法 其语法格式为:chmod [w ...

  9. Activity 设置切换动画

    extends://blog.csdn.net/luohaowang320/article/details/42124225 | http://blog.csdn.net/xuewater/artic ...

  10. vuls漏洞扫描工具

    Vuls 是一款适用于 Linux/FreeBSD 的漏洞扫描程序,无代理,采用 Go 语言编写,对于系统管理员来说,每天必须执行安全漏洞分析和软件更新都是一个负担. 为避免生产环境宕机,系统管理员通 ...