链接

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. js里的匿名函数 数组排序

    // 匿名函数:其实就是函数的简写形式 var method =function(){ alert("123"); } method(); // 匿名函数可以用于事件的处理 fun ...

  2. mysql聚集索引的优缺点

    聚簇索引并不是一种单独的索引类型,而是一种数据存储方式(不是数据结构,而是存储结构),具体细节依赖于其实现方式,但innodb的聚簇索引实际上是在同一个结构中保存了btree索引和数据行. 当表有索引 ...

  3. java面试每日一题5

    题目:企业发放的奖金根据利润提成.利润(I)低于或等于10万元时,奖金可提10%:利润高于10万元,低于20万元时,低于10万元的部分按10%提 成,高于10万元的部分,可可提成7.5%:20万到40 ...

  4. ACM题目————A除以B

    本题要求计算A/B,其中A是不超过1000位的正整数,B是1位正整数.你需要输出商数Q和余数R,使得A = B * Q + R成立. 输入格式: 输入在1行中依次给出A和B,中间以1空格分隔. 输出格 ...

  5. python实现删除文件与目录的方法

    os.remove(path) 删除文件 path. 如果path是一个目录, 抛出 OSError错误.如果要删除目录,请使用rmdir().os.rmdir()只能删除空目录 remove() 同 ...

  6. html 标签学习

    form 属性 定义和用法 enctype 属性规定在发送到服务器之前应该如何对表单数据进行编码. 默认地,表单数据会编码为 "application/x-www-form-urlencod ...

  7. 窗体移动API

    //窗体移动API [DllImport("user32.dll")] public static extern bool ReleaseCapture(); [DllImport ...

  8. HDU 5640 King's Cake

    King's Cake Problem Description It is the king's birthday before the military parade . The ministers ...

  9. 在HTML5规范中div中读取预存的data-[key]值

    HTML 代码: <div id="div_test" data-test="this is test" ></div> jQuery ...

  10. Oracle中如何使用REGEXP_SUBSTR函数

    REGEXP_SUBSTR函数格式如下: function REGEXP_SUBSTR(String, pattern, position, occurrence, modifier) __srcst ...