POJ-1981 Circle and Points 单位圆覆盖
题目链接: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 单位圆覆盖的更多相关文章
- bzoj1338: Pku1981 Circle and Points单位圆覆盖
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1338 1338: Pku1981 Circle and Points单位圆覆盖 Time ...
- poj1981 Circle and Points 单位圆覆盖问题
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud Circle and Points Time Limit: 5000MS Me ...
- 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的圆,那么在两圆交弧 ...
- poj1981Circle and Points(单位圆覆盖最多的点)
链接 O(n^3)的做法: 枚举任意两点为弦的圆,然后再枚举其它点是否在圆内. 用到了两个函数 atan2反正切函数,据说可以很好的避免一些特殊情况 #include <iostream> ...
- poj 1981(单位圆覆盖最多点问题模板)
Circle and Points Time Limit: 5000MS Memory Limit: 30000K Total Submissions: 7327 Accepted: 2651 ...
- poj1981 Circle and Points
地址:http://poj.org/problem?id=1981 题目: Circle and Points Time Limit: 5000MS Memory Limit: 30000K To ...
- POJ 1981 最大点覆盖问题(极角排序)
Circle and Points Time Limit: 5000MS Memory Limit: 30000K Total Submissions: 8346 Accepted: 2974 ...
- 【POJ 1981】Circle and Points(已知圆上两点求圆心坐标)
[题目链接]:http://poj.org/problem?id=1981 [题意] 给你n个点(n<=300); 然后给你一个半径R: 让你在平面上找一个半径为R的圆; 这里R=1 使得这个圆 ...
随机推荐
- UML用户指南--UML图简介
本节和大家一起学习一下UML图,这里主要介绍UML结构图和UML行为图两部分,下面让我们一起看一下UML图的详细介绍吧. UML图 这里再次提到对软件体系结构进行可视化.详述.构造和文档化,有5种最重 ...
- windows store app 拷贝文件到pc目录
(function () { "use strict"; WinJS.Binding.optimizeBindingReferences = true; var app = Win ...
- Mac OS系统 - 将视频转换成gif
github中开源轻量级应用:droptogif
- Elasticsearch基础概念理解
熟悉ES中的几个关键概念: 节点(Node):一个elasticsearch运行的实例,其实就是一个java进程.一般情况下,一台机器运行在一台机器上. 集群(Cluster): 好几个有相同集群名称 ...
- 《ASP.NET 本质论》HttpApplication的处理管道 ,HttpMoudle,HttpHandler
http://blog.csdn.net/sky1069/article/details/6659667 handler :http://blog.csdn.net/keymo_/article/de ...
- Tesseract 3 语言数据的训练方法
OCR,光学字符识别 光学字符识别(OCR,Optical Character Recognition)是指对文本资料进行扫描,然后对图像文件进行分析处理,获取文字及版面信息的过程.OCR技术非常专业 ...
- Hbase 0.96 比 hbase 0.94的改变
转载:http://blog.csdn.net/hxpjava1/article/details/20043703 环境: hadoop:hadoop-2.2.0 hbase:hbase-0.96.0 ...
- PHP strip_tags() 函数
定义和用法 strip_tags() 函数剥去 HTML.XML 以及 PHP 的标签. 语法 strip_tags(string,allow) 参数 描述 string 必需.规定要检查的字符串. ...
- 文件过滤驱动实现目录重定向(一)good
文件过滤驱动拦截的IRP主要包括以下几个:IRP_MJ_CREATE,文件创建操作,文件的任何操作,都是从这里开始的.IRP_MJ_CLEANUP,文件的HANDLE句柄全部关闭会触发这个消息IRP_ ...
- Android MediaStore与Media.EXTERNAL_CONTENT_URI
MediaStore这个类是Android系统提供的一个多媒体数据库,android中多媒体信息都可以从这里提取.这个MediaStore包括了多媒体数据库的所有信息,包括音频,视频和图像,andro ...