Circle and Points
Time Limit: 5000MS   Memory Limit: 30000K
Total Submissions: 8131   Accepted: 2899
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. 

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 翻译:给定平面坐标N个点,现在想用一个单位圆覆盖尽可能多的点,问最多能覆盖多少点。
思路:朴素做法:枚举任意两个点,求出过这两个点的单位圆的圆心,在看看这个这个单位圆能覆盖多少点,取最大即可。
AC代码:
#define _CRT_SECURE_NO_DEPRECATE
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<queue>
#include<set>
#include<vector>
#include<cstring>
#include<string>
#include<functional>
#include<cmath>
#include<stack>
using namespace std;
#define INF 0x3f3f3f3f
const int N_MAX=+;
double EPS = 1e-;
struct P {
double x, y;
P(double x=,double y=):x(x),y(y){}
}ps[N_MAX];
int N; //距离平方
double dist(const P&a,const P&b) {
return (a.x - b.x)*(a.x - b.x)+(a.y - b.y)*(a.y - b.y);//!!!!
}
//找圆心
P find_circle(const P& p1,const P& p2,int flag) {
double phi = atan2(p2.y-p1.y,p2.x-p1.x);
double d = sqrt(dist(p1, p2));
double theta = flag*acos(d/)+phi;
P c;
c.x = p1.x + cos(theta);
c.y = p1.y + sin(theta);
return c;
} void solve() {
int res = ;
for (int i = ; i < N;i++) {
for (int j = i+; j < N;j++) {
if (dist(ps[i], ps[j])<=) {//两点距离小于2,可在一个圆上
P c1 = find_circle(ps[i], ps[j], );
P c2 = find_circle(ps[i], ps[j], -);
int num1=, num2=;
for (int k = ; k < N;k++) {
if (k != i&&k != j) {
if (dist(c1, ps[k]) <= )num1++;
if (dist(c2, ps[k]) <= )num2++;
}
}
res = max(res, num1);
res = max(res, num2);
}
}
}
printf("%d\n",res);
} int main() {
while (scanf("%d",&N)&&N) {
for (int i = ; i < N;i++) {
scanf("%lf%lf",&ps[i].x,&ps[i].y);
}
if (N == ) { printf("1\n"); continue; }
solve();
}
return ;
}

思路2:我们先考虑其中的两个点,分别以这两个点为圆心画单位圆,如果两点距离足够近,则两圆一定会相交并且分别有一段相交的弧,不妨考虑其中的一段弧,如果我们最终需要找的那个圆的圆心就在这段弧上,那么这个圆一定会经过刚才所考虑的那两个点。那么我们每次固定一个点,以这个点为圆心画单位圆与其他的N-1个点为圆心的单位圆分别相交,会在这个点为圆心的圆上产生很多的相交弧,则最终那个圆的圆心若在相交弧重叠部分越多的地方,则可以包含更多的点。

AC代码:

#define _CRT_SECURE_NO_DEPRECATE
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<queue>
#include<set>
#include<vector>
#include<cstring>
#include<string>
#include<functional>
#include<cmath>
#include<stack>
using namespace std;
#define INF 0x3f3f3f3f
const int N_MAX=+;
double EPS = 1e-;
struct P {
double x, y;
P(double x=,double y=):x(x),y(y){}
}ps[N_MAX];
int N;
struct Bow {
double angle;
bool flag;//0代表初始,1代表终止
bool operator <(const Bow&b)const {
return this->angle < b.angle;
}
}bow[N_MAX];
//距离的平方
double dist(const P&a,const P&b) {
return (a.x - b.x)*(a.x - b.x)+(a.y - b.y)*(a.y - b.y);//!!!!
} void solve() {
int res_max = ;//res_max记录单位圆能包含的最多的顶点数
for (int i = ; i < N;i++) {//对于每一个点
int k = ;//记录交弧的个数
for (int j = ; j < N; j++) {
double d = sqrt(dist(ps[i], ps[j]));
if (j != i&&d <= ) {//i,j为圆心的圆相交
double phi = acos(d / );
double theta = atan2(ps[j].y - ps[i].y, ps[j].x - ps[i].x);
bow[k].angle = theta - phi; bow[k++].flag = ;
bow[k].angle = theta + phi; bow[k++].flag = ;
}
}
int res = ;//当前单位圆能包含的顶点数
sort(bow, bow + k);
for (int l = ; l < k;l++) {
if (!(bow[l].flag))res++;
else res--;
res_max = max(res_max, res);
}
}
printf("%d\n",res_max);
} int main() {
while (scanf("%d",&N)&&N) {
for (int i = ; i < N;i++) {
scanf("%lf%lf",&ps[i].x,&ps[i].y);
}
solve();
}
return ;
}

poj 1981 Circle and Points的更多相关文章

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

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

  2. poj1981 Circle and Points

    地址:http://poj.org/problem?id=1981 题目: Circle and Points Time Limit: 5000MS   Memory Limit: 30000K To ...

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

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

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

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

  5. POJ 1981 最大点覆盖问题(极角排序)

    Circle and Points Time Limit: 5000MS   Memory Limit: 30000K Total Submissions: 8346   Accepted: 2974 ...

  6. poj 1981(单位圆覆盖最多点问题模板)

    Circle and Points Time Limit: 5000MS   Memory Limit: 30000K Total Submissions: 7327   Accepted: 2651 ...

  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

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

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

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

随机推荐

  1. NSStream实现发送和接受数据

    一.基本概念在iOS中以NSStream(流)来发送和接收数据,可以设置流的代理,对流状态的变化做出相应.1连接建立2接收到数据3连接关闭NSStream:数据流的父类,用于定义抽象特性,例如:打开. ...

  2. iOS 打印系统字体

    NSArray * array = [UIFont familyNames]; for( NSString *familyName in array ){ printf( "Family: ...

  3. const 修饰成员函数 前后用法(effective c++ 03)

    目录 const在函数后面 const修饰成员函数的两个作用 const在函数前面 总结 const在函数后面 类的成员函数后面加 const,表明这个函数不会对这个类对象的数据成员(准确地说是非静态 ...

  4. 对O(logN)复杂度的推导

    之前一直对O(logN)这个复杂度如何推导出的存在疑问,这段时间看了一些算法相关的内容,正好看到这个问题,大略研究了一下算是基本解答了我的疑惑:现记录如下 假设有一棵高为H的满二叉树,则它的节点共有N ...

  5. GoF23种设计模式之结构型模式之代理模式

    一.概述 为其他对象提供一种代理以控制对这个对象的访问. 二.适用性 1.远程代理(RemoteProxy):为一个对象在不同的地址空间土工局部代表. 2.虚代理(VirtualProxy):根据需要 ...

  6. usb driver编写 (转)

    在开头补上LDD3的一句话:如果 USB 驱动没有和另一种处理用户和设备交互的子系统(例如 input, tty, video, 等待)关联, 驱动可使用 USB 主编号为了使用传统的和用户空间之间的 ...

  7. zigbee 中 OSAL 事件传递机制和消息传递机制

    一.概述 OSAL (Operating System Abstraction Layer) ,翻译为"操作系统抽象层". OSAL 就是一种支持多任务运行的系统资源分配机制.OS ...

  8. Phonegap环境配置和安装插件

    一:安装好jdk(配置好环境变量) 二:安装好Android SDK(配置好环境变量path F:\Android\android-sdk-windows\platform-tools;F:\Andr ...

  9. HDU 2852 KiKi's K-Number 主席树

    题意: 要求维护一个数据结构,支持下面三种操作: \(0 \, e\):插入一个值为\(e\)的元素 \(1 \, e\):删除一个值为\(e\)的元素 \(2 \, a \, k\):查询比\(a\ ...

  10. MIME类型-服务端验证上传文件的类型

    MIME的作用 : 使客户端软件,区分不同种类的数据,例如web浏览器就是通过MIME类型来判断文件是GIF图片,还是可打印的PostScript文件. web服务器使用MIME来说明发送数据的种类, ...