hdu 1077 Catching Fish 计算几何+暴力枚举
2013-05-07 09:10
274 查看
简单的暴力枚举,枚举两个点在圆上,用向量法求下圆心。复杂度o(n^3),但数据量只有300
/* author:jxy lang:C/C++ university:China,Xidian University **If you need to reprint,please indicate the source** */ #include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #define INF 1E9 using namespace std; double X[301],Y[301]; int n,ans; double x,y; inline double c(int i) { return (X[i]-x)*(X[i]-x)+(Y[i]-y)*(Y[i]-y); } int calc()//计数 { int i,ans=0; for(i=0;i<n;i++) { if(c(i)>1.0+1e-8)continue; ans++; } return ans; } void center(int i,int j)//确定圆心 { double x1=X[i]-X[j],y1=Y[i]-Y[j],len,k; double a,b;//单位向量 if(x1==0) a=1,b=0; else if (y1==0) a=0,b=1; else { k=-1/y1*x1; len=sqrt(1+k*k); a=1.0/len; b=k/len; } len=1-(x1*x1+y1*y1)/4; if(len<0)return; len=sqrt(len); x1=(X[i]+X[j])/2.0;y1=(Y[i]+Y[j])/2.0; a*=len;b*=len; x=x1+a;y=y1+b; ans=max(ans,calc()); x=x1-a;y=y1-b; ans=max(ans,calc()); } int main() { int T; int i,j; scanf("%d",&T); while(T--) { scanf("%d",&n); for(i=0;i<n;i++) scanf("%lf%lf",&X[i],&Y[i]); ans=0; for(i=0;i<n;i++) for(j=i;j<n;j++) center(i,j); printf("%d\n",ans); } }
相关文章推荐
- HDU 1270 小希的数表 (暴力枚举+数学)
- hdu 3720 暴力枚举
- hdu 5143 暴力枚举,转换的思想
- HDU 1238 Substrings(KMP+暴力枚举)
- hdu 5952 Counting Cliques 暴力枚举+优化
- 暴力枚举,dfs(连连看,HDU 4272)
- HDU 5726 GCD(枚举暴力)
- HDU 3697(H) ——Selecting courses(暴力枚举,贪心)
- HDU 1431 素数回文-暴力枚举
- HDOJ/HDU 1015 Safecracker(枚举、暴力)
- hdu 2328 暴力枚举+find()
- hdu 5128 The E-pang Palace(计算几何,暴力枚举)
- hdu 5203 Rikka with wood sticks (暴力枚举边)
- hdu 4770 Lights Against Dudely(暴力枚举dfs)
- HDU 4445Crazy Tank 2012金华现场赛D题(暴力枚举)
- Hdu 5961 传递【暴力枚举】
- HDU 1598 find the most comfortable road 【暴力枚举 + 并查集】
- hdu 1407 1248 暴力枚举
- HDOJ/HDU 1015 Safecracker(枚举、暴力)
- hdu 4968(暴力枚举)