1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
| const int maxN=50000; Point p[maxN]; Point ch[maxN]; int n; int len;
int main() { int t,l; //scanf("%d",&t); while(~scanf("%d",&n)) {
double distence=0.0; for(int i=0; i<n; i++) { scanf("%lf%lf",&p[i].x,&p[i].y); } if(n==0) break; //这是一些值得特判的情况 //if(n==0) if(n==1) if(n==2) if(n<=1) { printf("0.50\n"); continue; } if (n == 2) { printf("%.2lf\n",dis(p[0],p[1])*0.50+0.50); continue; }
Graham_scan(p,ch,n,len);
for(int i=0; i<len; i++) //凸包 各个顶点的顺序 cout<<ch[i].x<<" "<<ch[i].y<<endl;
//求凸包的周长 double perimeters=0.0; for(int i=1;i<len;i++) { perimeters+=dis(ch[i],ch[i-1]); } perimeters+=dis(ch[0],ch[len-1]); printf("%.0lf\n",perimeters);
//求凸包的面积 double area=0.0; for(int i=2; i<len; i++) { area+=mul(ch[i-1],ch[i],ch[0]); } printf("%d\n",(int )area/100);
//求图包最小圆覆盖 double maxr = -1; double a, b, c, r, s; for (int i=0; i<len; i++) //枚举凸包上的点 { for (int j=i+1; j<len; j++) { for (int k=j+1; k<len; k++) { a = dis(ch[i], ch[j]); b = dis(ch[i], ch[k]); c = dis(ch[j], ch[k]); if (a*a+b*b<c*c || a*a+c*c<b*b || b*b+c*c<a*a) r = max(max(a, b), c) / 2.0;//钝角时 半径为最长边的一半 else { s = fabs(mul(ch[i], ch[j], ch[k])) / 2.0; r = a * b * c / (s * 4.0);//三角形外接圆公式 } if (maxr < r) maxr = r; } } } printf ("%.2lf\n", maxr+0.50); //if(t) printf("\n"); //这是控制两组输出数据之间有一个空格的 } return 0; }
|