地址: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. mac 环境配置

    安装homebrew 用于安装各种软件 eg:brew search qq 查看qq安装目录 brew install 复制刚刚查看到的目录安装qq 安装 oh my zsh 自动补全目录跳转 1.安 ...

  2. 转:Android文件操作总结

    http://www.cnblogs.com/devinzhang/archive/2012/01/19/2327597.html http://blog.sina.com.cn/s/blog_5a4 ...

  3. shell基础篇(一)从hello world开始

    前记:这里是我做的shell笔记:接下来会提供一系列. Shell是一种脚本语言,那么,就必须有解释器来执行这些脚本.Unix/Linux上常见的Shell脚本解释器有bash.sh.csh.ksh等 ...

  4. lua常用操作

    1 .Lua生成随机数: Lua 生成随机数需要用到两个函数:math.randomseed(xx), math.random([n [, m]]) 1. math.randomseed(n) 接收一 ...

  5. iGson

    头文件 #import <Foundation/Foundation.h> #import <objc/runtime.h> #import "NSString+Ut ...

  6. HTTP/2笔记之开篇

    前言 本系列基于HTTP/2第17个草案文档,地址就是:https://tools.ietf.org/html/draft-ietf-httpbis-http2-17. HTTP/2规范已经通过发布批 ...

  7. Lucene中最简单的索引和搜索示例

    package com.jiaoyiping.lucene; import org.apache.lucene.analysis.standard.StandardAnalyzer; import o ...

  8. 拦截chrome的console.log输出

    console.log = function(){}; 这样 console.log(123) 将不会在输出任何调试信息

  9. .net Asp AdRotator(广告控件)

    1.新建项目名称AdRotator 2.右键项目名称添加一个xml文件命名为AdRotator.xml <?xml version="1.0" encoding=" ...

  10. Java多线程(4)----线程的四种状态

    与人有生老病死一样,线程也同样要经历开始(等待).运行.挂起和停止四种不同的状态.这四种状态都可以通过Thread类中的方法进行控制.下面给出了Thread类中和这四种状态相关的方法. 1 // 开始 ...