题目链接:http://poj.org/problem?id=1981

  容易想到直接枚举两个点,然后确定一个圆来枚举,算法复杂度O(n^3).

  这题还有O(n^2*lg n)的算法。将每个点扩展为单位圆,依次枚举每个单位圆,枚举剩下的单位圆,如果有交点,每个圆产生两个交点,然后对产生的2n个交点极角排序,判断被覆盖最多的弧,被覆盖相当于这个弧上的点为圆心的圆可以覆盖到覆盖它的那些点,所以被覆盖最多的弧就是答案了。

O(n^3):

 //STATUS:C++_AC_4032MS_208KB
#include <functional>
#include <algorithm>
#include <iostream>
//#include <ext/rope>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;
//using namespace __gnu_cxx;
//define
#define pii pair<int,int>
#define mem(a,b) memset(a,b,sizeof(a))
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define PI acos(-1.0)
//typedef
typedef long long LL;
typedef unsigned long long ULL;
//const
const int N=;
const int INF=0x3f3f3f3f;
const int MOD=,STA=;
const LL LNF=1LL<<;
const double EPS=1e-;
const double OO=1e15;
const int dx[]={-,,,};
const int dy[]={,,,-};
const int day[]={,,,,,,,,,,,,};
//Daily Use ...
inline int sign(double x){return (x>EPS)-(x<-EPS);}
template<class T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T> inline T lcm(T a,T b,T d){return a/d*b;}
template<class T> inline T Min(T a,T b){return a<b?a:b;}
template<class T> inline T Max(T a,T b){return a>b?a:b;}
template<class T> inline T Min(T a,T b,T c){return min(min(a, b),c);}
template<class T> inline T Max(T a,T b,T c){return max(max(a, b),c);}
template<class T> inline T Min(T a,T b,T c,T d){return min(min(a, b),min(c,d));}
template<class T> inline T Max(T a,T b,T c,T d){return max(max(a, b),max(c,d));}
//End struct Node{
double x,y;
}nod[N],O;
int n; double dist(Node &a,Node &b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
} void getO(Node &a,Node &b,int dir)
{
double t=dist(a,b)/2.0;
t=dir*sqrt((1.0-t*t));
if(a.y==b.y){
O.x=(a.x+b.x)/2.0;
O.y=a.y+t;
}
else if(a.x==b.x){
O.y=(a.y+b.y)/2.0;
O.x=a.x+t;
}
else {
double kt;
kt=atan(-(a.x-b.x)/(a.y-b.y));
O.x=(a.x+b.x)/2.0+cos(kt)*t;
O.y=(a.y+b.y)/2.0+sin(kt)*t;
}
} int main()
{
// freopen("in.txt","r",stdin);
int i,j,k,ans,tot;
while(scanf("%d",&n) && n)
{
ans=;
for(i=;i<n;i++){
scanf("%lf%lf",&nod[i].x,&nod[i].y);
}
for(i=;i<n;i++){
for(j=i+;j<n;j++){
if(dist(nod[i],nod[j])<2.0){
getO(nod[i],nod[j],);
for(tot=,k=;k<n;k++){
if(k==i || k==j)continue;
if(dist(O,nod[k])-1.0<EPS)tot++;
}
if(tot>ans)ans=tot;
}
}
} printf("%d\n",ans);
}
return ;
}

O(n^2*lg n): 建立极角的时候,不是以枚举的圆心 i->j 方向的向量,而是 j->i 方向的向量,因为 i->j 方向不能完全判断圆的方向,在极角排序的时候会出错。

 //STATUS:C++_AC_750MS_212KB
#include <functional>
#include <algorithm>
#include <iostream>
//#include <ext/rope>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;
//using namespace __gnu_cxx;
//define
#define pii pair<int,int>
#define mem(a,b) memset(a,b,sizeof(a))
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define PI acos(-1.0)
//typedef
typedef long long LL;
typedef unsigned long long ULL;
//const
const int N=;
const int INF=0x3f3f3f3f;
const int MOD=,STA=;
const LL LNF=1LL<<;
const double EPS=1e-;
const double OO=1e15;
const int dx[]={-,,,};
const int dy[]={,,,-};
const int day[]={,,,,,,,,,,,,};
//Daily Use ...
inline int sign(double x){return (x>EPS)-(x<-EPS);}
template<class T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T> inline T lcm(T a,T b,T d){return a/d*b;}
template<class T> inline T Min(T a,T b){return a<b?a:b;}
template<class T> inline T Max(T a,T b){return a>b?a:b;}
template<class T> inline T Min(T a,T b,T c){return min(min(a, b),c);}
template<class T> inline T Max(T a,T b,T c){return max(max(a, b),c);}
template<class T> inline T Min(T a,T b,T c,T d){return min(min(a, b),min(c,d));}
template<class T> inline T Max(T a,T b,T c,T d){return max(max(a, b),max(c,d));}
//End struct Node{
double x,y;
}nod[N];
struct Point{
double angle;
int id;
bool operator < (const Point& a)const{
return angle!=a.angle?angle<a.angle:id>a.id;
}
}p[N*];
int n; double dist(Node &a,Node &b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
} int slove()
{
int i,j,ans,tot,k,cnt;
ans=;
for(i=;i<n;i++){
for(j=k=;j<n;j++){
if(j==i || dist(nod[i],nod[j])>2.0)continue;
double angle=atan2(nod[i].y-nod[j].y,nod[i].x-nod[j].x); //注意为i-j的向量方向
double phi=acos(dist(nod[i],nod[j])/);
p[k].angle=angle-phi;p[k++].id=;
p[k].angle=angle+phi;p[k++].id=-;
}
sort(p,p+k);
for(tot=,j=;j<k;j++){
tot+=p[j].id;
ans=Max(ans,tot);
}
}
return ans;
} int main()
{
// freopen("in.txt","r",stdin);
int i;
while(~scanf("%d",&n) && n)
{
for(i=;i<n;i++)
scanf("%lf%lf",&nod[i].x,&nod[i].y); printf("%d\n",slove());
}
return ;
}

POJ-1981 Circle and Points 单位圆覆盖的更多相关文章

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

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

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

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

  3. poj 1981 Circle and Points

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

  4. POJ 1981 Circle and Points (扫描线)

    [题目链接] http://poj.org/problem?id=1981 [题目大意] 给出平面上一些点,问一个半径为1的圆最多可以覆盖几个点 [题解] 我们对于每个点画半径为1的圆,那么在两圆交弧 ...

  5. poj1981Circle and Points(单位圆覆盖最多的点)

    链接 O(n^3)的做法: 枚举任意两点为弦的圆,然后再枚举其它点是否在圆内. 用到了两个函数 atan2反正切函数,据说可以很好的避免一些特殊情况 #include <iostream> ...

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

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

  7. poj1981 Circle and Points

    地址:http://poj.org/problem?id=1981 题目: Circle and Points Time Limit: 5000MS   Memory Limit: 30000K To ...

  8. POJ 1981 最大点覆盖问题(极角排序)

    Circle and Points Time Limit: 5000MS   Memory Limit: 30000K Total Submissions: 8346   Accepted: 2974 ...

  9. 【POJ 1981】Circle and Points(已知圆上两点求圆心坐标)

    [题目链接]:http://poj.org/problem?id=1981 [题意] 给你n个点(n<=300); 然后给你一个半径R: 让你在平面上找一个半径为R的圆; 这里R=1 使得这个圆 ...

随机推荐

  1. hdu 1427 dfs

    速算24点 题意:随机给你四张牌,包括 A(1),2,3,4,5,6,7,8,9,10,J(11),Q(12),K(13).要求只用'+','-','*','/'运算符以及括号改变运算 顺序,使得最终 ...

  2. sbrk and coreleft

    一.sbrk 函数来源:TC2.0.Linux 函数名: sbrk 功 能: 增加程序可用数据段空间,增加大小由参数 incr决定 . 返回值:函数调用成功返回一指针,指向新的内存空间.函数调用失败则 ...

  3. Unity3d Shader开发(三)Pass(Texturing )

    纹理在基本的顶点光照被计算后被应用.在着色器中通过SetTexture 命令来完成.   SetTexture 命令在片面程序被使用时不会生效:这种模式下像素操作被完全描述在着色器中. 材质贴图可以用 ...

  4. 关于 js 2个数组取差集怎么取

    关于 js 2个数组取差集怎么取? 例如求var arr1 = [1]; var arr2 = [1,2];的差集方法一: Array.prototype.diff = function(a) { r ...

  5. .net 访问远程的MSSQL报System.AccessViolationException错误的解决方法

    访问远程的数据库时 报错,本地数据库正常 netsh winsock reset   --运行此命令,解决. netsh winsock reset命令,作用是重置 Winsock 目录.如果一台机器 ...

  6. Mongodb使用总结

    学习Mongodb已经有半年多了,为啥学习它,工作需要啊.好了,废话不说,总结在实际项目应用中的几点问题. 学习总结 首先,mongodb基本上既照顾到了sql某些语法,又有nosql的许多优点.入门 ...

  7. POJ 2195 Going Home(最小费用最大流)

    http://poj.org/problem?id=2195 题意 :  N*M的点阵中,有N个人,N个房子.让x个人走到这x个房子中,只能上下左右走,每个人每走一步就花1美元,问当所有的人都归位了之 ...

  8. 过生日,也要学学哈,这次是SHELL的GETOPTS

    今天是WEBSOCKET,, 先完成一个SHELL的GETOPS,周一就用得着. #!/bin/bash echo "usage: ./$0 -t (prism|opscripts)&quo ...

  9. mysql查看'datadir'目录

    mysql查看创建的数据库的数据,包含表等存放的目录,可以输入下面指令查看: show variables like 'datadir'

  10. Where is the ActiveX Project Type for Delphi 10.1 Berlin

    n 10.1 Berlin the ActiveX project types are missing from the New Items Window under Delphi. They are ...