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 使得这个圆 ...
随机推荐
- easyui 汉化问题
遇到 easyui 需要汉化的 , 1: 找到 汉化文件 ,文件位于 插件的 locale 文件夹 内 easyui-lang-zh_CN.js 2: 将其 加载 与 easyui 之后 <s ...
- C语言字符知识狭区
C语言字符在用户接口软件编程上经常用到,但是有一些狭区会让编程出现一些小BUG,现在总结与此. 1.'\\' 代表的是字符\,而'\'是不能代表字符\的.通常\后面都要跟上数字或者其他字母来表示一个特 ...
- 敏捷开发概述与路线(转自MBAlib)
敏捷开发的概述 简单的说,敏捷开发是一种以人为核心.迭代.循序渐进的开发方法.在敏捷开发中,软件项目的构建被切分成多个子项目,各个子项目的成果都经过测试,具备集成和可运行的特征.换言之,就是把一个大项 ...
- jquery 插件页面回到顶部
引用: jquery.scrollUp.min.js js: $.scrollUp({ scrollName: 'scrollUp', // Element ID topDistance: '300' ...
- Java之向左添加零(000001)
int i_m = 270000 ; String str_m = String.valueOf(i_m); String str ="000000"; str_m=str.sub ...
- [XJOI NOI2015模拟题13] B 最小公倍数 【找规律】
题目链接:XJOI - NOI2015-13 - B 题目分析 通过神奇的观察+打表+猜测,有以下规律和性质: 1) 删除的 n 个数就是 1~n. 2) 当 c = 2 时,如果 n + 1 是偶数 ...
- Codeforces Round #209 (Div. 2)
A: 要么是两次要么4次,判断是否在边界: #include<cstdio> using namespace std; int main() { int n,m,x; ; scanf(&q ...
- SecureCRT 中文乱码问题
1.修改远程linux机器的配置 [root@rhel ~]#vi /etc/sysconfig/i18n 把LANG改成支持UTF-8的字符集 如: LANG=”zh_CN.UTF-8″ 或者是 L ...
- 查看jdk的位数
public class Test { public static void main(String[] args) { System.out.println("bit of JVM is ...
- 李洪强漫谈iOS开发[C语言-020]-scanf的本质
scanf是有返回值和参数的