[日常摸魚]HDU1348Wall-凸包
阿新 • • 發佈:2018-01-18
str 答案 name reg 成了 題意 sort int pac
我學習進度慢得連我自己都怕…
題意:大概給$n$個點搞出它的凸包,然後還要在凸包外弄一層厚為$l$的東西,求這個東西的周長
我個滯漲居然把pi開成了int…搞了一個晚上才看見
凸包直接求,因為是凸多邊形所以答案就是凸包的周長加上$2 \pi l$
#include<cstdio> #include<cmath> #include<algorithm> using namespace std; const int N=1005; const double pi=acos(-1); struct Point { double x,y; Point(double x=0,double y=0):x(x),y(y){} }p[N]; int T,n,L; int q[N]; inline Point operator - (Point a,Point b) { return Point(a.x-b.x,a.y-b.y); } inline double Cross(Point a,Point b) { return a.x*b.y-a.y*b.x; } inline double sqr2(double x){return x*x;} inline double lenght(Point a,Point b) { returnsqrt(sqr2(a.x-b.x)+sqr2(a.y-b.y)); } inline bool cmp(const Point &a,const Point &b) { if(a.x==b.x)return a.y<b.y; return a.x<b.x; } inline int convexHull() { sort(p+1,p+n+1,cmp); int m=0; for(register int i=1;i<=n;i++) { while(m>=2&&Cross(p[q[m]]-p[q[m-1]],p[i]-p[q[m-1]])<=0)m--; q[++m]=i; } int k=m; for(register int i=n-1;i>=1;i--) { while(m>k&&Cross(p[q[m]]-p[q[m-1]],p[i]-p[q[m-1]])<=0)m--; q[++m]=i; } if(n>1)m--; return m; } int main() { scanf("%d",&T); while(T--) { scanf("%d%d",&n,&L); for(register int i=1;i<=n;i++)scanf("%lf%lf",&p[i].x,&p[i].y); int m=convexHull();double ans=0; for(register int i=2;i<=m;i++)ans+=lenght(p[q[i]],p[q[i-1]]); ans+=lenght(p[q[m]],p[q[1]]); ans+=2*pi*L; printf("%.0lf\n",ans); if(T)printf("\n"); } return 0; }
[日常摸魚]HDU1348Wall-凸包