The Shape of Donggua 工大的原创几何题 挺好,顶一下。
2012-08-13 22:05
363 查看
/*就是用凸包和旋转卡壳求一个最远点对和最近的距离。 这个最近的距离定义为用两条平行直线将多边形包围时直线中的所有距离里求最小即可。 只需要在卡到最远点跳出while循环时记录下此时最远点到边的距离即可。 我用叉积来记录。然后不断更新最小值即可。*/ #include <stdio.h> #include <iostream> #include <algorithm> #include <cmath> #define ll 0.618-0.1 #define rr 0.618+0.1 #define inf 9999999999.0 #define eps 1e-8 using namespace std; struct point { double x,y; } res[10001],p[10001]; int n,top; double cross(point a,point b,point o) { return (a.x-o.x)*(b.y-o.y)-(b.x-o.x)*(a.y-o.y); } double dis(point a,point b) { return ((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)); } bool cmp(point a,point b) { if(a.x-b.x>eps||b.x-a.x>eps) return a.x<b.x; return a.y<b.y; } void graham() { sort(p,p+n,cmp); res[0] = p[0]; res[1] = p[1]; top = 1; for(int i=2; i<n; i++) { while(top&&cross(p[i],res[top-1],res[top])<=0) --top; res[++top] = p[i]; } int ntop = top; res[++top] = p[n-2]; for(int i=n-3; i>=0; i--) { while(top>ntop&&cross(p[i],res[top-1],res[top])<=0) --top; res[++top] = p[i]; } } int main() { while(scanf("%d",&n)==1) { for(int i=0; i<n; i++) scanf("%lf%lf",&p[i].x,&p[i].y); graham(); int q=1; double L=0,S=0; double min=inf; double sum=0; for(int i=0; i<top; i++) { while(fabs(cross(res[i],res[i+1],res[q]))<fabs(cross(res[i],res[i+1],res[q+1]))) q=(q+1)%top; L=max(L,max(dis(res[i],res[q]),dis(res[i+1],res[q+1]))); sum=fabs(cross(res[i],res[i+1],res[q])); S=sum/sqrt(dis(res[i],res[i+1])); if(S<min) min=S; } L=sqrt(L); double t=min/L; if(t>=ll&&t<=rr) printf("Proper\n"); else if(t<ll) printf("Thin\n"); else if(t>rr) printf("Fat\n"); } return 0; }
相关文章推荐
- [hoj 2742]The Shape of Donggua[凸包][Graham Scan][旋转卡壳]
- NEUOJ 1210(The number of triangulation-计算几何+剪枝)
- UVA 11800 - Determine the Shape 几何
- 数学几何____Determine the Shape(uva 11800)
- Shape of HDU_hdu_2108(几何).java
- 【计算几何】HDU 2108 Shape of HDU 凸包
- UVA 11800 - Determine the Shape 几何
- UVA11800--Determine the Shape(计算几何)
- Shape + Selector: Make a Shape as one item of the Selector
- POJ 2242 The Circumference of the Circle (计算几何)
- SPOJ CIRU The area of the union of circles (计算几何)
- 【计算几何初步-判断是否凸多边形】【HDU2108】Shape of HDU
- 【原创】mybatis配置文件报错:The content of element type "configuration" must match "(properties>settings>typeAliases>typeHa...
- uva 438 - The Circumference of the Circle(几何)
- 简单几何(四边形形状) UVA 11800 Determine the Shape
- 【原创】The Design and Implementation of OO Model of Fetion Engine
- 【计算几何初步-判断是否凸多边形】【HDU2108】Shape of HDU
- 先把同事的原创贴上 - Tip of the Day --for Using Emacs
- some error of the Oracle connection TNS-03505 OR TNS-12541(原创)
- POJ2242_The Circumference of the Circle(几何/三角形外接圆周长/模板)