POJ - 1981 :Circle and Points (圆的扫描线) hihocoder1508
题意:给定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的更多相关文章
- poj 1981 Circle and Points
Circle and Points Time Limit: 5000MS Memory Limit: 30000K Total Submissions: 8131 Accepted: 2899 ...
- POJ 1981 Circle and Points (扫描线)
[题目链接] http://poj.org/problem?id=1981 [题目大意] 给出平面上一些点,问一个半径为1的圆最多可以覆盖几个点 [题解] 我们对于每个点画半径为1的圆,那么在两圆交弧 ...
- poj1981 Circle and Points
地址:http://poj.org/problem?id=1981 题目: Circle and Points Time Limit: 5000MS Memory Limit: 30000K To ...
- poj1981 Circle and Points 单位圆覆盖问题
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud Circle and Points Time Limit: 5000MS Me ...
- bzoj1338: Pku1981 Circle and Points单位圆覆盖
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1338 1338: Pku1981 Circle and Points单位圆覆盖 Time ...
- HDU5299 圆的扫描线 && 树上删边博弈
HDU5299 圆的扫描线 && 树上删边博弈 标签(空格分隔): 未分类 给出若干个圆,可以互相嵌套但不相交或相切. 每次删去一个圆和它内部的圆,进行博弈,问谁赢. 分成两部分.首先 ...
- POJ 1981 最大点覆盖问题(极角排序)
Circle and Points Time Limit: 5000MS Memory Limit: 30000K Total Submissions: 8346 Accepted: 2974 ...
- hdu3511 Prison Break 圆的扫描线
地址:http://acm.split.hdu.edu.cn/showproblem.php?pid=3511 题目: Prison Break Time Limit: 10000/5000 MS ( ...
- poj 1981(单位圆覆盖最多点问题模板)
Circle and Points Time Limit: 5000MS Memory Limit: 30000K Total Submissions: 7327 Accepted: 2651 ...
随机推荐
- python数据分析5 数据转换
1数据转换 数据转换时数据准备的重要环节,它通过数据平滑,数据聚集,数据概化,规范化等凡是将数据转换成适用于数据挖掘的形式 1.1 数据平滑 去除数据中的噪声,将连续数据离散化.这里可以采用分箱.聚类 ...
- 【搬运工】RHEL6.5 移植使用CentOS 的YUM 步骤
转载地址:http://www.cnblogs.com/rchen98/p/6056469.html 问题:使用 Red Hat Enterprise Linux Server(RHEL) yum安装 ...
- MOOC python笔记(二)python中的数据类型和基本语句
python数据类型 数字类型 整数(int) 与数学中整数概念一致(数字大小没有限制,这和其他语言不同),整数可正可负,默认情况下,整数采用十进制.其他进制需要增加相应的引导符号. 如果是二进制在前 ...
- 静下心来学jquery的用法
http://blog.csdn.net/xiaojun1288/article/details/6803552
- C#中真正的属性
引言 我们以前课堂上说的类当中的“属性”,其实官方叫法是“字段”或者“域”域(Field).正常使用,把它们当属性理解更加方便快捷,也没有什么问题. 如果要在微软的mvc中充分利用类带来的便利,就有必 ...
- POI SXSSF API 导出1000万数据示例
SXSSF是XSSF API的兼容流式扩展,在必须生成非常大的电子表格.并且堆空间有限时使用. SXSSF通过限制对滑动窗口内数据的访问实现低内存占用,而XSSF允许访问文档中的所有行. 不在窗口中的 ...
- 正则-RegExp
正则-RegExp 正则,是一条规则,用于检验字符串格式,目标就是字符串: 只要是表单提交的数据都是字符串 定义: 1,var reg=/格式/ 2,var reg=new regexp() 方法: ...
- English--动词时态
English|动词时态 时态是一个很玄乎的东西,要么是完全掌握,要么是不知所云. 在正式开始之前,大家需要明白汉语的谓语动词是不会随着时间与状态而变化.但是,英语的谓语动词会随着时间与状态发生变化. ...
- Spring的配置文件找不到元素 'beans' 的声明
Spring的配置文件找不到元素 'beans' 的声明 一般是由Spring的版本导致的,你可以尝试使用如下的某一种. <?xml version="1.0" encodi ...
- 【转载】C#通过Clone方法快速创建相同架构的DataTable
在C#中的Datatable数据变量的操作过程中,如果需要克隆当前DataTable变量的结构,包括所有 DataTable 架构和约束等信息,可以使用DataTable中的Clone方法来实现,Cl ...