hdu 1348 wall (计算几何,凸包)
2015-03-15 21:26
405 查看
题目链接:hdu 1348
凸包模板题。但是要注意输出格式,我开始就被输出格式给坑了。。。
凸包模板题。但是要注意输出格式,我开始就被输出格式给坑了。。。
#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #include<cmath> using namespace std; #define maxn (1000+10) int N,L; double pi=acos(-1); struct node{ int x,y; }p[maxn],point,stack[maxn]; inline int read(){ int x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } int get_cross(node a,node b,node c){ return ((b.x-a.x)*(c.y-a.y)-(b.y-a.y)*(c.x-a.x)); } double get_dis(node a,node b){ return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)); } void find_point(){ int col=0; node temp; point=p[0]; for(int i=1;i<N;i++){ if(p[i].y<point.y||(p[i].y==point.y&&p[i].x<point.x)){ point=p[i]; col=i; } } temp=p[0]; p[0]=p[col]; p[col]=temp; } bool cmp(node a,node b){ int K=get_cross(point,a,b); if(K<0)return true; if(K>0)return false; double xx=get_dis(point,a),yy=get_dis(point,b); return xx<yy; } void Graham(){ int top=2; p =p[0]; stack[0]=p[0]; stack[1]=p[1]; stack[2]=p[2]; for(int i=3;i<=N;i++){ while(top>1&&get_cross(stack[top-1],stack[top],p[i])>=0)top--; stack[++top]=p[i]; } double ans=0; node temp=stack[top],sai=temp; top--; while(top){ node xx=stack[top]; top--; ans+=get_dis(xx,temp); temp=xx; } ans+=get_dis(sai,temp); ans+=pi*L*2; printf("%.0lf\n",ans); } int main(){ int T=read(); while(T--){ N=read(); L=read(); for(int i=0;i<N;i++){ p[i].x=read(); p[i].y=read(); } find_point(); sort(p,p+N,cmp); Graham(); if(T!=0)printf("\n");//注意未在最后一组数据时要输出换行符,否则会PE } return 0; }
相关文章推荐
- hdu 1348:Wall(计算几何,求凸包周长)
- 计算几何 ( 凸包 )——Wall ( HDU 1248 )
- poj1113——Wall(计算几何凸包)
- [计算几何-凸包]pku1113-Wall
- POJ 1113 || HDU 1348: wall(凸包问题)
- POJ 1113 || HDU 1348: wall(凸包问题)
- hdu 1348 Wall(凸包模板)
- hdu 1392:Surround the Trees(计算几何,求凸包周长)
- hdu 2108 Shape of HDU(计算几何:凸包)
- HDU 1348 wall 凸包模板题 求周长
- hdu 1348 Wall(凸包模板题)
- 2013 多校第七场 hdu 4667 Building Fence(计算几何、凸包)
- POJ 1113 Wall (计算几何-凸包)
- hdu 4946 Area of Mushroom 计算几何(凸包)
- HDU 3692 Shade of Hallelujah Mountain (计算几何,三维空间点的旋转,二维凸包)
- HDU 4667 Building Fence 计算几何 凸包+圆
- POJ 1113 Wall (计算几何-凸包)
- hdu 1348 Wall 凸包模板题
- 【计算几何】HDU 2108 Shape of HDU 凸包
- hdu 1348 Wall(凸包模板题 Graham)