题意:给定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. kube-prometheus部署

    一.从git拉取相应yaml文件 git clone https://github.com/coreos/kube-prometheus.git 二.修改grafana及prometheus的serv ...

  2. SuperMemo

    SuperMemo Your friend, Jackson is invited to a TV show called SuperMemo in which the participant is ...

  3. 【java】获取客户端访问的公网ip和归属地

    import com.alibaba.druid.support.json.JSONUtils; import org.thymeleaf.util.StringUtils; import javax ...

  4. Android studio中遇到的问题

    首先声明只是Android studio使用中遇到的问题纯属个人学习笔记,有什么不对的可以留言. 将脱壳后的java文件拖入到Android studio android studio 首先提示是ER ...

  5. 第十一节:Asp.Net Core 之内容缓存(IMemoryCache)

    1. 整体说明 ASP.NET Core 支持多种不同的缓存,最简单的缓存基于 IMemoryCache,它表示存储在 Web 服务器内存中的缓存,内存缓存可以存储任何对象,存储形式键值对,需要 .n ...

  6. linux 重启jmeter服务

    #!/bin/bash #jmeter kill and start echo -e '\033[32m--------Jmeter---------------\033[0m' echo " ...

  7. 对ssm框架里面的一些常用注解的理解

    @Componcnt :作用就是把当前类对象存入spring容器中 属性:value 用于指定bean的id 当我们不写的时候默认就是当前类名,并且首字母要小写 ------------------- ...

  8. jQuery中使用Ajax获取JSON格式数据示例代码

    JSON(JavaScript Object Notation)是一种轻量级的数据交换格式.JSONM文件中包含了关于“名称”和“值”的信息.有时候我们需要读取JSON格式的数据文件,在jQuery中 ...

  9. Mybatis 原理分析

    对于入门程序的流程分析 使用过程 读配置文件 读取配置文件时绝对路径和相对路径(web工程部署后没有src路径)都有一定问题,实际开发中一般有两种方法 使用类加载器,它只能读取类路径的配置文件 使用S ...

  10. Java自学-接口与继承 对象转型

    Java中的对象转型 示例 1 : 明确引用类型与对象类型的概念 首先,明确引用类型与对象类型的概念 在这个例子里,有一个对象 new ADHero(), 同时也有一个引用ad 对象是有类型的, 是A ...