From 8ef2e29769454ecd12320f096190e5e2ae4205bf Mon Sep 17 00:00:00 2001 From: ljcjames Date: Fri, 12 Aug 2022 16:44:44 +0800 Subject: [PATCH] =?UTF-8?q?=E2=80=9C=E5=80=9F=E9=89=B4=E2=80=9D=E5=88=AB?= =?UTF-8?q?=E4=BA=BA=E7=9A=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 8.10/I-Wall/main.cpp | 98 ++++++++++++++++++++++++++------------------ 1 file changed, 57 insertions(+), 41 deletions(-) diff --git a/8.10/I-Wall/main.cpp b/8.10/I-Wall/main.cpp index a76bcc7..87072e8 100644 --- a/8.10/I-Wall/main.cpp +++ b/8.10/I-Wall/main.cpp @@ -1,65 +1,81 @@ +//参考别人的 #include #include #include #include #include using namespace std; -const double pi=acos(-1.00),eps = 1e-6;//pi3.14~ -const int N=1001,inf=0x3f3f3f3f; +const double pi=acos(-1.00),eps = 1e-8;//pi3.14~ +const int N=1005,inf=0x3f3f3f3f; double ans=0; -struct dot{ - int x,y; -}d[N]; -stacks; +int q[N],n; +struct Point{ + double x,y; + Point () {}//无参的构造函数,及初始化、赋初值 + Point (double xx,double yy) :x(xx),y(yy) {} + Point friend operator - (Point a,Point b) + { + return Point(a.x-b.x,a.y-b.y); + } + double friend operator ^ (Point a,Point b) + { + return a.x*b.y-a.y*b.x; + } + bool friend operator < (Point a,Point b) + { + if(a.y==b.y ) return a.xs; int sign(double d) { if(fabs(d)0? 1:-1; } -double cross(double x1, double y1, double x2, double y2) +//double cross(double x1, double y1, double x2, double y2) +//{ +// return x1 * y2 - x2 * y1; +//} +double dist(Point a,Point b) { - return x1 * y2 - x2 * y1; + Point c=a-b; + return sqrt(c.x*c.x+c.y*c.y);//CE double } -double length(int x1,int y1,int x2,int y2) +bool cmp(Point a,Point b) { - int x=x1-x2,y=y1-y2; - return sqrt((double)x*x+y*y);//CE double + int s=sign((a-p[1])^(b-p[1])); + if(s>0||(s==0&&dist(a,p[1])1&&sign((p[q[top]]-p[q[top-1]])^(p[i]-p[q[top]]))<=0){ + top--; + } + q[++top]=i; + } + double res=0; + for(int i=1;i=sign(cross(d[f].x-d[ff].x,d[f].y-d[ff].y,d[j].x-d[ff].x,d[j].y-d[ff].y))) - { - ans-=length(d[f].x,d[f].y,d[ff].x,d[ff].y); -// printf("--%d(%d,%d),%d(%d,%d): -%lf=%lf\n",f,d[f].x,d[f].y,ff,d[ff].x,d[ff].y,length(d[f].x,d[f].y,d[ff].x,d[ff].y),ans); - f=s.top(); - s.pop(); - if(s.empty()) break;//RE - ff=s.top(); - } - ans+=length(d[j].x,d[j].y,d[f].x,d[f].y); -// printf("++%d(%d,%d),%d(%d,%d): +%lf=%lf\n",j,d[j].x,d[j].y,f,d[f].x,d[f].y,length(d[j].x,d[j].y,d[f].x,d[f].y),ans); - s.push(f); - s.push(j); - } -// printf("%d ",s.size()); - printf("%.0lf",ans+2*l*pi);//WA*2 (周长跟多边形形状有关)错了,无关,自带四舍五入 + printf("%d",(int)(Graham()+pi*2*l+0.5));//(int)()记得加括号 return 0; }