【题目链接】 http://poj.org/problem?id=1981

【题目大意】

  给出平面上一些点,问一个半径为1的圆最多可以覆盖几个点

【题解】

  我们对于每个点画半径为1的圆,那么在两圆交弧上的点所画的圆,一定可以覆盖这两个点
  我们对于每个点计算出其和其它点的交弧,对这些交弧计算起末位置对于圆心的极角,
  对这些我们进行扫描线操作,统计最大交集数量就是答案。

【代码】

#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
using namespace std;
double EPS=1e-10;
double add(double a,double b){
if(abs(a+b)<EPS*(abs(a)+abs(b)))return 0;
return a+b;
}
const int MAX_N=310;
struct P{
double x,y;
P(){}
P(double x,double y):x(x),y(y){}
P operator + (P p){return P(add(x,p.x),add(y,p.y));}
P operator - (P p){return P(add(x,-p.x),add(y,-p.y));}
P operator * (double d){return P(x*d,y*d);}
double dot(P p){return add(x*p.x,y*p.y);} //点积
double det(P p){return add(x*p.y,-y*p.x);} //叉积
}ps[MAX_N];
double dist(P p,P q){return sqrt((p-q).dot(p-q));}
struct PolarAngle{
double angle;
bool flag;
}as[MAX_N];
bool cmp_a(PolarAngle a,PolarAngle b){
return a.angle<b.angle;
}
int solve(int n,double r){
int ans=1;
for(int i=0;i<n;i++){
int m=0; double d;
for(int j=0;j<n;j++){
if(i!=j&&(d=dist(ps[i],ps[j]))<=2*r){
double phi=acos(d/2);
double theta=atan2(ps[j].y-ps[i].y,ps[j].x-ps[i].x);
as[m].angle=theta-phi,as[m++].flag=1;
as[m].angle=theta+phi,as[m++].flag=0;
}
}sort(as,as+m,cmp_a);
for(int sum=1,j=0;j<m;j++){
if(as[j].flag)sum++;
else sum--;
ans=max(ans,sum);
}
}return ans;
}
int N;
int main(){
while(scanf("%d",&N),N){
for(int i=0;i<N;i++)scanf("%lf%lf",&ps[i].x,&ps[i].y);
printf("%d\n",solve(N,1.0));
}return 0;
}

POJ 1981 Circle and Points (扫描线)的更多相关文章

  1. poj 1981 Circle and Points

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

  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 (圆的扫描线) hihocoder1508

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

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

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

  9. 【POJ 1981 】Circle and Points

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

随机推荐

  1. JS格式化时间(支持小程序,兼容IOS)

    })-(\d{})-(\d{})T(\d{}):(\d{}):(\d{})/ /** * @function format time * @param val, format * @return {s ...

  2. Cannot resolve symbol ‘Component’ & Cannot resolve symbol ‘PropTypes’

    import React, { Component, PropTypes } from 'react' 报错:Cannot resolve symbol 'Component' Cannot reso ...

  3. Ubuntu下安装LNMP之nginx的安装

    Nginx 最初是作为一个 Web 服务器创建的,用于解决 C10k 的问题.作为一个 Web 服务器,它可以以惊人的速度为您的数据服务.但 Nginx 不仅仅是一个 Web 服务器,你还可以将其用作 ...

  4. Mysql History list length 值太大引起的问题

    1. 环境 Mysql 主从 Mysql版本:5.1.49-log 系统:Red Hat Enterprise Linux Server release 5.4  64bit 2. 表面现象 数据库操 ...

  5. Input操作文件

    在HTML表单中,可以上传文件的唯一控件就是<input type="file">. 注意:当一个表单包含<input type="file" ...

  6. jquery序列化表单

    没有使用其他的东西 , 数据传送是最基本的. 前台: var info = $('#dataForm').serialize() ; alert(decodeURIComponent(info,tru ...

  7. Spring + Mybatis - 原始dao开发整合 与 Mapper代理整合

    Spring + Mybatis - 原始dao开发整合 与 Mapper代理整合 标签: mybatisSpringbeanApplicationContextMapper 2015-12-31 1 ...

  8. C++ Review

    #include "iostream" #include "iomanip" #include "cstdio" using namespa ...

  9. HDU4889 Scary Path Finding Algorithm

    Fackyyj loves the challenge phase in TwosigmaCrap(TC). One day, he meet a task asking him to find sh ...

  10. [bzoj3231][SDOI2008]递归数列——矩阵乘法

    题目大意: 一个由自然数组成的数列按下式定义: 对于i <= k:ai = bi 对于i > k: ai = c1ai-1 + c2ai-2 + ... + ckai-k 其中bj和 cj ...