“借鉴”别人的
This commit is contained in:
parent
349b318ffd
commit
8ef2e29769
|
@ -1,65 +1,81 @@
|
||||||
|
//参考别人的
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include<stack>
|
#include<stack>
|
||||||
using namespace std;
|
using namespace std;
|
||||||
const double pi=acos(-1.00),eps = 1e-6;//pi3.14~
|
const double pi=acos(-1.00),eps = 1e-8;//pi3.14~
|
||||||
const int N=1001,inf=0x3f3f3f3f;
|
const int N=1005,inf=0x3f3f3f3f;
|
||||||
double ans=0;
|
double ans=0;
|
||||||
struct dot{
|
int q[N],n;
|
||||||
int x,y;
|
struct Point{
|
||||||
}d[N];
|
double x,y;
|
||||||
stack<int>s;
|
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.x<b.x;
|
||||||
|
return a.y<b.y;
|
||||||
|
}
|
||||||
|
}p[N];
|
||||||
|
//stack<int>s;
|
||||||
int sign(double d)
|
int sign(double d)
|
||||||
{
|
{
|
||||||
if(fabs(d)<eps) return 0;
|
if(fabs(d)<eps) return 0;
|
||||||
return d>0? 1:-1;
|
return 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;
|
int s=sign((a-p[1])^(b-p[1]));
|
||||||
return sqrt((double)x*x+y*y);//CE double
|
if(s>0||(s==0&&dist(a,p[1])<dist(b,p[1])))return 1;
|
||||||
|
else return 0;
|
||||||
|
}
|
||||||
|
double Graham()
|
||||||
|
{
|
||||||
|
sort(p+1,p+n+1);
|
||||||
|
sort(p+1,p+1+n,cmp);
|
||||||
|
int top=3;
|
||||||
|
q[1]=1,q[2]=2,q[3]=3;
|
||||||
|
for(int i=4;i<=n;i++)
|
||||||
|
{
|
||||||
|
while(top>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<top;i++)
|
||||||
|
{
|
||||||
|
res+=dist(p[q[i]],p[q[i+1]]);
|
||||||
|
}
|
||||||
|
return res+dist(p[q[1]],p[q[top]]);
|
||||||
}
|
}
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
int n,l,minn=1,f,ff,x0,x1,x2,y1,y2,y0;
|
int l,minn=1,f,ff,x0,x1,x2,y1,y2,y0;
|
||||||
scanf("%d%d",&n,&l);
|
scanf("%d%d",&n,&l);
|
||||||
for(int i=1;i<=n;i++)
|
for(int i=1;i<=n;i++)
|
||||||
{
|
{
|
||||||
scanf("%d%d",&d[i].x,&d[i].y);//&!!!
|
scanf("%lf%lf",&p[i].x,&p[i].y);//&!!!
|
||||||
minn=d[i].y<d[minn].y? i:minn;
|
|
||||||
}
|
}
|
||||||
int j=(n+minn-2)%n+1;
|
printf("%d",(int)(Graham()+pi*2*l+0.5));//(int)()记得加括号
|
||||||
// s.push(minn%n+1);
|
|
||||||
s.push(minn);
|
|
||||||
s.push(j);
|
|
||||||
ans+=length(d[j].x,d[j].y,d[minn].x,d[minn].y);//漏了初始的边
|
|
||||||
while(j!=minn)
|
|
||||||
{
|
|
||||||
j=(j+n-2)%n+1;
|
|
||||||
f=s.top();
|
|
||||||
s.pop();
|
|
||||||
ff=s.top();
|
|
||||||
while(0>=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 (周长跟多边形形状有关)错了,无关,自带四舍五入
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue