标签:node noi dia lap image center ide inline stdout
1 #include <bits/stdc++.h> 2 #define ll long long 3 #define eps 1e-8 4 using namespace std; 5 inline int read(){ 6 int x=0;int f=1;char ch=getchar(); 7 while(!isdigit(ch)) {if(ch==‘-‘) f-=-1;ch=getchar();} 8 while(isdigit(ch)) {x=x*10+ch-‘0‘;ch=getchar();} 9 return x*f; 10 } 11 const int MAXN=1e6+10; 12 struct node{ 13 double x,y; 14 }s[MAXN],p[MAXN],t[10]; 15 int top,n; 16 double ans=1e60; 17 inline bool operator < (node n,node m){ 18 return abs(n.y-m.y)<eps?n.x<m.x:n.y<m.y; 19 } 20 inline node operator + (node n,node m){ 21 node t;t.x=n.x+m.x;t.y=n.y+m.y;return t; 22 } 23 inline node operator - (node n,node m){ 24 node t;t.x=n.x-m.x;t.y=n.y-m.y;return t; 25 } 26 inline double operator * (node n,node m){ 27 return n.x*m.y-n.y*m.x; 28 } 29 inline node operator * (node n,double m){ 30 node t;t.x=n.x*m;t.y=n.y*m;return t; 31 } 32 inline int dcmp(node n,node m){ 33 return n.x-m.x<eps&&n.y-m.y<eps; 34 } 35 inline double dis(node n){ 36 return sqrt(n.x*n.x+n.y*n.y); 37 } 38 inline bool mycmp(node n,node m){ 39 double t=(n-p[1])*(m-p[1]); 40 if(abs(t)<eps) return dis(n-p[1])-dis(m-p[1])<0; 41 else return t>0; 42 } 43 inline double operator / (node n,node m){//dianji 44 return n.x*m.x+n.y*m.y; 45 } 46 void graham(){ 47 for(int i=2;i<=n;i++){ 48 if(p[i]<p[1]) swap(p[i],p[1]); 49 } 50 sort(p+2,p+n+1,mycmp); 51 s[++top]=p[1]; 52 for(int i=2;i<=n;i++){ 53 while(top>1&&(s[top]-s[top-1])*(p[i]-s[top])<eps) top--; 54 s[++top]=p[i]; 55 } 56 s[0]=s[top]; 57 } 58 void RC(){ 59 int l=1,r=1,p=1; 60 double R,L,D,H; 61 for(int i=0;i<top;i++){ 62 D=dis(s[i]-s[i+1]); 63 while((s[i+1]-s[i])*(s[p+1]-s[i])-(s[i+1]-s[i])*(s[p]-s[i])>-eps) p=(p+1)%top; 64 while((s[i+1]-s[i])/(s[r+1]-s[i])-(s[i+1]-s[i])/(s[r]-s[i])>-eps) r=(r+1)%top; 65 if(i==0) l=r; 66 while((s[i+1]-s[i])/(s[l+1]-s[i])-(s[i+1]-s[i])/(s[l]-s[i])<eps) l=(l+1)%top; 67 L=(s[i+1]-s[i])/(s[l]-s[i])/D;R=(s[i+1]-s[i])/(s[r]-s[i])/D; 68 H=(s[i+1]-s[i])*(s[p]-s[i])/D; 69 if(H<0) H=-H; 70 //cout<<l<<‘ ‘<<r<<endl; 71 double tmp=(R-L)*H; 72 if(tmp<ans){ 73 ans=tmp; 74 t[0]=s[i]+(s[i+1]-s[i])*(R/D); 75 t[1]=t[0]+(s[r]-t[0])*(H/dis(t[0]-s[r])); 76 t[2]=t[1]-(t[0]-s[i])*((R-L)/dis(s[i]-t[0])); 77 t[3]=t[2]-(t[1]-t[0]); 78 } 79 } 80 } 81 int main(){ 82 //freopen("All.in","r",stdin); 83 //freopen("a.out","w",stdout); 84 n=read(); 85 for(int i=1;i<=n;i++){ 86 scanf("%lf%lf",&p[i].x,&p[i].y); 87 } 88 graham(); 89 RC(); 90 printf("%.5lf\n",ans); 91 int fir=0; 92 for(int i=1;i<=3;i++){ 93 if(t[i]<t[fir]) fir=i; 94 } 95 for(int i=0;i<=3;i++){ 96 printf("%.5lf %.5lf\n",t[(i+fir)%4].x,t[(i+fir)%4].y); 97 } 98 return 0; 99 }
旋转卡壳
标签:node noi dia lap image center ide inline stdout
原文地址:http://www.cnblogs.com/something-for-nothing/p/8007276.html