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 ...
随机推荐
- docker 学习操作记录 2
记录2 [BEGIN] // :: Connecting to ... Connection established. To escape to local shell, press Ctrl+Alt ...
- Appium+iOS真机环境搭建
安装目录 1.macOS系统 10.12.6 2.xcode 9.0 3.appium Desktop 1.12.1 4.node.js node -v npm 5.cnpm npm insta ...
- nginx mysqlnd驱动引擎提升mysql性能
nginx mysqlnd驱动引擎提升mysql性能 前期要安装 mysql mysqli pdo_mysql libiconv 1 先去PHP官网下个 php-5.6.29.tar.gz wget ...
- python(二)面向对象知识点
模块 别名 import my_module as xxx(别名) 先导入内置模块 再导入第三方模块 再导入自定义模块 from my_module(导入的文件) import *(变量) __all ...
- Go语言系列教程(十二)之函数完结篇
Hello,各位小伙伴大家好,我是小栈君.上一期我们讲到了关于函数的有参.无参.匿名函数,本期我们分享一下关于go语言函数类型.匿名函数和闭包的概念和实战.闲话不多说,立马开始分享. 在Go语言中,函 ...
- Django中使用CORS实现跨域请求(转)
原文:https://blog.csdn.net/zizle_lin/article/details/81381322 跨域请求: 请求url包含协议.网址.端口,任何一种不同都是跨域请求. ...
- 【题解】最长递增路径 [51nod1274]
[题解]最长递增路径 [51nod1274] 传送门:最长递增路径 \([51nod1274]\) [题目描述] 一个可能有自环有重边的无向图,每条边都有边权.输入两个整数 \(n,m\) 表示一共 ...
- mybatis中用注解如何处理存储过程返回的多个结果集?
sql代码: create procedure sptest.getnamesanditems() reads sql data dynamic result sets 2 BEGIN ATOMIC ...
- 利用cv与matplotlib.pyplot读图片与显示图片
import matplotlib.pyplot as pltimport cv2 as cva=cv.imread('learn.jpg')cv.imshow('learn',a)fig=plt.f ...
- 2019 找钢网java面试笔试题 (含面试题解析)
本人5年开发经验.18年年底开始跑路找工作,在互联网寒冬下成功拿到阿里巴巴.今日头条.找钢网等公司offer,岗位是Java后端开发,因为发展原因最终选择去了找钢网,入职一年时间了,也成为了面试官 ...