题意:给定N个点,然后给定一个半径为R的圆,问这个圆最多覆盖多少个点。

思路:在圆弧上求扫描线。

如果N比较小,不难想到N^3的算法。 一般这种覆盖问题你可以假设有两个点在圆的边界上,那么每次产生的圆去看多少个点在园内即可。

但是我们现在要更高效的做法。题目等价于,有N个半径为R的圆,问二维平面上一点最多被多少个圆覆盖。即我们可以每次求交,交的部分标记++;

hihocoder1508的代码。

#include<bits/stdc++.h>
#define pdd pair<double,int>
#define f first
#define s second
#define rep(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
const int maxn=;
const double eps=1e-;
const double pi=acos(-1.0);
struct point{ double x,y;}p[maxn];
double det(point a,point b){ return a.x*b.y-a.y*b.x;}
double dot(point a,point b){ return a.x*b.x+a.y*b.y;}
point operator +(point a,point b){ return point{a.x+b.x,a.y+b.y}; }
point operator -(point a,point b){ return point{a.x-b.x,a.y-b.y}; }
double dist(point a,point b){ return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));}
int dcmp(double x){ if(fabs(x)<eps) return ; return x>?:-;}
pdd a[maxn]; int ans,N; double ang1,ang2,R;
void CirinterCir(point a,point b)
{
double L=dist(a,b)/,t=acos(L/R);
double base=atan2(b.y-a.y,b.x-a.x);
ang1=base+t,ang2=base-t;
}
bool check(point i,point j)
{
double ang=(ang1+ang2)/;
point x=point{i.x+R*cos(ang),i.y+R*sin(ang)};
return dcmp(dist(x,j)-R)<=;
}
void solve()
{
rep(i,,N) {
int cnt=,Mx,tot=;
rep(j,,N) {
if(i==j||dist(p[i],p[j])>R+R) continue;
if(p[i].x==p[j].x&&p[i].y==p[j].y) { cnt++; continue;}
CirinterCir(p[i],p[j]);
if(ang1>ang2) swap(ang1,ang2);
if(check(p[i],p[j])){
a[++tot]=pdd(ang1-eps,-);
a[++tot]=pdd(ang2,);
}
else {
a[+tot]=pdd(-pi-eps,-);
a[++tot]=pdd(ang1,);
a[++tot]=pdd(ang2-eps,-);
a[++tot]=pdd(pi,);
}
}
sort(a+,a+tot+); Mx=cnt;
rep(i,,tot){
if(a[i].s==-) cnt++;
else cnt--;
Mx=max(Mx,cnt);
}
ans=max(ans,Mx);
}
}
int main()
{
scanf("%d%lf",&N,&R);
rep(i,,N) scanf("%lf%lf",&p[i].x,&p[i].y);
solve();
printf("%d\n",ans);
return ;
}

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

  1. poj 1981 Circle and Points

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

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

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

  3. poj1981 Circle and Points

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

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

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

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

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

  6. HDU5299 圆的扫描线 && 树上删边博弈

    HDU5299 圆的扫描线 && 树上删边博弈 标签(空格分隔): 未分类 给出若干个圆,可以互相嵌套但不相交或相切. 每次删去一个圆和它内部的圆,进行博弈,问谁赢. 分成两部分.首先 ...

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

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

  8. hdu3511 Prison Break 圆的扫描线

    地址:http://acm.split.hdu.edu.cn/showproblem.php?pid=3511 题目: Prison Break Time Limit: 10000/5000 MS ( ...

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

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

随机推荐

  1. volatile 和 内存屏障

    接下来看看volatile是如何解决上面两个问题的: 被volatile修饰的变量在编译成字节码文件时会多个lock指令,该指令在执行过程中会生成相应的内存屏障,以此来解决可见性跟重排序的问题. 内存 ...

  2. 25个led灯新玩法

    Microbit板子的25个led灯,是5X5的阵列,led(lights emitting diodes)中文叫发光二极管,有单向导电性,还发光,有各种颜色的,红,蓝,黄等等.mPython可以让你 ...

  3. Delphi BusinessSkinForm使用说明

    1.先放bsBusinessSkinForm.bsSkinData.bsStoredSkin各一个到窗体上 2.修改bsBusinessSkinForm的SkinData属性为bsSkinData1 ...

  4. 『正睿OI 2019SC Day6』

    动态规划 \(dp\)早就已经是经常用到的算法了,于是老师上课主要都在讲题.今天讲的主要是三类\(dp\):树形\(dp\),计数\(dp\),\(dp\)套\(dp\).其中计数\(dp\)是我很不 ...

  5. 【LeetCode】633. Sum of Square Numbers

    Difficulty: Easy  More:[目录]LeetCode Java实现 Description https://leetcode.com/problems/sum-of-square-n ...

  6. .NET Core解析DNS域名或主机名的方法

    在.NET Core中我们可以用System.Net.Dns类来解析域名或主机名的IP地址,我们新建一个.NET Core控制台项目,写入下面代码: using System; using Syste ...

  7. 使用php函数防止SQL注入方法

    什么是SQL注入? SQL注入是指在你系统防御之外,某人将一段Mysql语句注入到你的数据库.注入通常发生在系统要求用户输入数据的时候,比如用户名的输入,用户可能输入的不是一个用户名,而是一段SQL语 ...

  8. React生命周期中应该做什么事

    React生命周期函数 装载组件触发 0.construct(props) 用来 props--->state 初始化state,并且把props转化为state 1.componentWill ...

  9. java。JDK的API,版本1.6.0中文版下载

    转载自https://blog.csdn.net/xiao9469/article/details/87783561 链接: https://pan.baidu.com/s/1YqrbTD_msTmn ...

  10. nlp学习杂记

    什么是 token embedding? 输入一个word,在字典里查找得到它对应的下标就是token,然后用该数字下标去lookup表查找得到该词对应的词向量(词嵌入)就是embedding wor ...