链接

O(n^3)的做法:

枚举任意两点为弦的圆,然后再枚举其它点是否在圆内。

用到了两个函数

atan2反正切函数,据说可以很好的避免一些特殊情况

 #include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<vector>
#include<cmath>
#include<queue>
#include<set>
using namespace std;
#define N 310
#define LL long long
#define INF 0xfffffff
const double eps = 1e-;
const double pi = acos(-1.0);
const double inf = ~0u>>;
struct point
{
double x,y;
point(double x = ,double y = ):x(x),y(y){}
}p[N];
double dis(point a,point b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
point getcircle(point p1,point p2)
{
point mid = point((p1.x+p2.x)/,(p2.y+p1.y)/);
double angle = atan2(p2.y-p1.y,p2.x-p1.x);
double d = sqrt(1.0-dis(p1,mid)*dis(p1,mid));
return point(mid.x+d*sin(angle),mid.y-d*cos(angle));
}
int dcmp(double x)
{
if(fabs(x)<eps)return ;
else return x<?-:;
}
int main()
{
int i,j,n;
while(scanf("%d",&n)&&n)
{
for(i = ;i <= n; i++)
scanf("%lf%lf",&p[i].x,&p[i].y);
int maxz = ;
for(i = ; i <= n; i++)
for(j = i+ ; j <= n ;j++)
{
if(dis(p[i],p[j])>2.0) continue;
int tmax = ;
point cir = getcircle(p[i],p[j]);
for(int g = ; g <= n ;g++)
{
if(dcmp(dis(cir,p[g])-1.0)>)
continue;
tmax++;
}
maxz = max(maxz,tmax);
}
printf("%d\n",maxz);
}
return ;
}

O(n^2log(n))

这个类似扫描线的做法,以每一个点为圆心化圆,枚举与其相交得圆,保存交点和角度,按角度排序后,扫一遍。

 #include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<vector>
#include<cmath>
#include<queue>
#include<set>
using namespace std;
#define N 310
#define LL long long
#define INF 0xfffffff
const double eps = 1e-;
const double pi = acos(-1.0);
const double inf = ~0u>>;
struct point
{
double x,y;
point(double x = ,double y = ):x(x),y(y) {}
} p[N];
struct node
{
double ang;
int in;
} arc[N*N];
double dis(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 ;
else return x<?-:;
}
bool cmp(node a,node b)
{
if(dcmp(a.ang-b.ang)==)
return a.in>b.in;
return dcmp(a.ang-b.ang)<;
}
int main()
{
int i,j,n;
while(scanf("%d",&n)&&n)
{
for(i = ; i <= n; i++)
scanf("%lf%lf",&p[i].x,&p[i].y);
int g = ;
int ans = ,maxz = ;
for(i = ; i <= n ; i++)
{
ans = ;
g = ;
for(j = ; j <= n ; j++)
{
if(dis(p[i],p[j])>2.0) continue;
double ang1 = atan2(p[j].y-p[i].y,p[j].x-p[i].x);
double ang2 = acos(dis(p[i],p[j])/);
arc[++g].ang = ang1-ang2;//这里角度的算法很巧妙
arc[g].in = ;
arc[++g].ang = ang1+ang2;
arc[g].in = -;
}
sort(arc+,arc+g+,cmp); //cout<<g<<endl;
for(j = ; j <= g;j++)
{
ans+=arc[j].in;
maxz = max(maxz,ans);
}
}
printf("%d\n",maxz);
}
return ;
}

poj1981Circle and Points(单位圆覆盖最多的点)的更多相关文章

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

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

  2. POJ-1981 Circle and Points 单位圆覆盖

    题目链接:http://poj.org/problem?id=1981 容易想到直接枚举两个点,然后确定一个圆来枚举,算法复杂度O(n^3). 这题还有O(n^2*lg n)的算法.将每个点扩展为单位 ...

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

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

  4. Codeforces 1036E Covered Points (线段覆盖的整点数)【计算几何】

    <题目链接> <转载于 >>>  > 题目大意: 在二维平面上给出n条不共线的线段(线段端点是整数),问这些线段总共覆盖到了多少个整数点. 解题分析: 用GC ...

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

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

  6. hdu 1077(单位圆覆盖问题)

    Catching Fish Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To ...

  7. bzoj AC倒序

    Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...

  8. poj 1981 Circle and Points

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

  9. Java for LeetCode 149 Max Points on a Line

    Given n points on a 2D plane, find the maximum number of points that lie on the same straight line. ...

随机推荐

  1. hashMap底层put和get方法逻辑

    1.hashmap put方法的实现: public V put(K key, V value) { if (key == null) return putForNullKey(value); int ...

  2. char*,wchar_t*,CString和BSTR之间的转换

    前言 本文并不尝试列举出所有的转换方法,只列举作者认为方便易用的方法. 1.char*和wchar_t*的相互转换 可以利用中间类_bstr_t(头文件comdef.h)方便的进行相互转换 const ...

  3. Codeforces Round #336 Marbles

    E. Marbles time limit per test:  2 seconds memory limit per test:  256 megabytes input:  standard in ...

  4. js post提交页面

    function post(URL, PARAMS) { var temp = document.createElement("form"); temp.action = URL; ...

  5. HDU(3790),最短路二级标准

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3790 最短路径问题 Time Limit: 2000/1000 MS (Java/Others)    ...

  6. Java中通过Selenium WebDriver定位iframe中的元素

    转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 问题:有一些元素,无论是通过id或是xpath等等,怎么都定位不到. 分析:这很可能是因为你要定位 ...

  7. centos 3d特效

    说下我怎么实现的吧 1.现在新力得里搜“XGL”和“Compiz”,把相关软件安装好. 2.安装ndivid的glx驱动: sudo apt-get install nvidia-kernel-com ...

  8. 使用JavaScript操作DOM节点元素的常用方法(创建/删除/替换/复制等)

    getElementById(id)这是通过id来访问某一元素,最常用的之一,例:<html><body><div id="myid">test ...

  9. MySQL PLSQL Demo - 005.IF THEN ELSEIF THEN ELSE END IF

    drop procedure if exists p_hello_world; create procedure p_hello_world(in v_id int) begin ) then sel ...

  10. UICollectionView 使用

    /** 初始化UICollectionView */ UICollectionViewFlowLayout *flowLayout=[[UICollectionViewFlowLayout alloc ...