地址: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. Serlvet学习笔记之二—不同页面共享数据

    一共有四种方法实现共享页面共享数据 1.cookie 2.sendRedirect 3.session 4.隐藏表单提交(form) 5.ServletContex 1.cookie:服务器在客户端保 ...

  2. oracle查锁表

    查锁表 select LOCK_INFO.OWNER || '.' || LOCK_INFO.OBJ_NAME as OBJ_NAME, -- 对象名称(已经被锁住) LOCK_INFO.SUBOBJ ...

  3. 十大Material Design开源项目

    介于拟物和扁平之间的Material Design自面世以来,便引起了很多人的关注与思考,就此产生的讨论也不绝于耳.本文详细介绍了在Android开发者圈子里颇受青睐的十个Material Desig ...

  4. 使用Editplus和Dev C++配置C++的编译运行环 境

    或许大家会有疑问,为何不直接使用VC;VS;或Dev这些IDE呢?何必舍近求远.主要是因为写程序这么多年来已经习惯了Editplus,包括他的快捷键,语法自动完成,语法提示等等,Editplus用了这 ...

  5. JSON.parse()和JSON.stringfy()

    JSON.parse()从字符串中解析出JSON对象: var data = '{"a":1,"b":2}'; JSON.parse(data); JSON.s ...

  6. u盘装系统,u盘安装win7系统教程

    http://www.upanboot.com/tool/anzhuang_win7.html 可以用本教程给笔记本.台式机.上网本和组装电脑通过U盘安装Win7系统. 步骤一.首先要准备一个至少8G ...

  7. DOS cmd - how to ping a remote host with specified port

    You can use ping to test whether you can connect to a remote host: ping baidu.com ping 125.6.45.88 ( ...

  8. 报错 ERROR in static/js/vendor.b3f56e9e0cd56988d890.js from UglifyJs

    开发vux项目在引入 // 表单验证组件-start import zh_CN from 'vee-validate/dist/locale/zh_CN' import Validator from ...

  9. Egret Wing4.0.3 合并资源图片问题

    一 发布项目时,选择合并图片资源 选择合图大小 发布后,图片合并.随机了图片名字.  二  随机名的问题 当资源不变更的情况下,多次发布,每次发布后资源的图片随机名是不变的. 现在改变preload组 ...

  10. 有限制的最短路spfa+优先队列

    poj1724 ROADS Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10751   Accepted: 3952 De ...