【题目链接】 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. Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) C

    C. Little Artem and Matrix time limit per test 2 seconds memory limit per test 256 megabytes input s ...

  2. Qt5 界面中文乱码问题

    1.文件所在项目文件  xxx.pro 中添加: QMAKE_CXXFLAGS += -execution-charset:utf- 2.文件以 UTF-8 编码保存 3.添加  utf-8 BOM

  3. SpringBoot入门学习(一): Idea 创建 SpringBoot 的 HelloWorld

    创建项目: 项目结构: 程序启动入口: 正式开始: package com.example.demo; import org.springframework.boot.SpringApplicatio ...

  4. web上传组件

    uploadify  jquery插件. common-fileipload; common-io ;jar

  5. 51Nod-1586-约数和

    #include <cstdio> using namespace std; typedef long long ll; ; int n, q; int cnt[MAXN]; ll a[M ...

  6. Web应用程序开发,基于Ajax技术的JavaScript树形控件

    感谢http://www.cnblogs.com/dgrew/p/3181769.html#undefined 在Web应用程序开发领域,基于Ajax技术的JavaScript树形控件已经被广泛使用, ...

  7. POJ 2395 Out of Hay (prim)

    题目链接 Description The cows have run out of hay, a horrible event that must be remedied immediately. B ...

  8. HBase表操作

    相对于0.9.X版本,在HBase1.X版本对内部API改动比较大,例如连接部分类库变更,如下: 连接获取:org.apache.hadoop.hbase.HBaseConfiguration.cre ...

  9. python面向对象之继承与派生

    一.继承 继承是一种创建新的类的方式,在python中,新建的类可以继承自一个或者多个父类,原始类称为基类或超类,新建的类称为派生类或子类. python中类的继承分为:单继承和多继承,如果是多继承的 ...

  10. POJ2680(动态规划,大数)

    Computer Transformation Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4548   Accepted ...