标签:des style blog http color os io strong
Time Limit: 3000MS | Memory Limit: 30000K | |
Total Submissions: 8173 | Accepted: 2423 |
Description
Input
Output
Sample Input
3 3 4 2 6 2 7 5 2 6 3 9 2 0 8 0 6 5 -1
Sample Output
0.50 27.00
Source
1 #include <math.h> 2 #include <stdio.h> 3 #include <string.h> 4 #include <stdlib.h> 5 #include <iostream> 6 #include <algorithm> 7 8 using namespace std; 9 10 #define eps 1e-8 11 #define MAXX 1000010 12 13 typedef struct point 14 { 15 16 double x; 17 double y; 18 }point; 19 20 bool dy(double x,double y){ 21 return x>y+eps; } 22 bool xy(double x,double y){ 23 return x<y-eps; } 24 bool dyd(double x,double y){ 25 return x>y-eps; } 26 bool xyd(double x,double y){ 27 return x<y+eps; } 28 bool dd(double x,double y){ 29 return fabs(x-y)<eps; } 30 31 double crossProduct(point a,point b,point c) 32 { 33 return (c.x-a.x)*(b.y-a.y)-(c.y-a.y)*(b.x-a.x); 34 } 35 36 double dist(point a,point b) 37 { 38 39 return sqrt((b.x-a.x)*(b.x-a.x)+(b.y-a.y)*(b.y-a.y)); 40 } 41 42 point c[MAXX]; 43 point stk[MAXX]; 44 int top; 45 46 bool cmp(point a,point b) 47 { 48 49 double len=crossProduct(c[0],a,b); 50 if(dd(len,0.0)) 51 return xy(dist(c[0],a),dist(c[0],b)); 52 return xy(len,0.0); 53 } 54 55 double max(double x,double y) 56 { 57 58 return xy(x,y) ? y : x; 59 } 60 61 void Graham(int n) 62 { 63 64 int tmp=0; 65 for(int i=1; i<n; i++) 66 { 67 68 if(xy(c[i].x,c[tmp].x) || dd(c[i].x,c[tmp].x) && xy(c[i].y,c[tmp].y)) 69 tmp=i; 70 } 71 swap(c[0],c[tmp]); 72 sort(c+1,c+n,cmp); 73 stk[0]=c[0]; 74 stk[1]=c[1]; 75 top=1; 76 for(int i=2; i<n; i++) 77 { 78 while(top>=1 && xyd(crossProduct(stk[top],stk[top-1],c[i]),0.0)) 79 top--; 80 stk[++top]=c[i]; 81 } 82 } 83 84 double rotating(int n) 85 { 86 int j=1,k=2; 87 double ans=0.0; 88 stk[n]=stk[0]; 89 for(int i=0; i<n; i++) 90 { 91 while(dy(fabs(crossProduct(stk[(k+1)%n],stk[i],stk[j])),fabs(crossProduct(stk[k],stk[i],stk[j])))) 92 k=(k+1)%n; 93 while(dy(fabs(crossProduct(stk[k],stk[i],stk[(j+1)%n])),fabs(crossProduct(stk[k],stk[i],stk[j])))) 94 j=(j+1)%n; 95 ans=max(ans,fabs(crossProduct(stk[k],stk[i],stk[j]))); 96 } 97 return ans*0.5; 98 } 99 100 int main() 101 { 102 103 int i,j,n; 104 while(scanf("%d",&n)!=EOF&&n != -1) 105 { 106 107 for(i=0; i<n; i++) 108 scanf("%lf%lf",&c[i].x,&c[i].y); 109 Graham(n);//printf("%d**",top); 110 double ans=rotating(top+1); 111 printf("%.2lf\n",ans); 112 } 113 return 0; 114 } 115
hdu 3934&&poj 2079 (凸包+旋转卡壳+求最大三角形面积),布布扣,bubuko.com
hdu 3934&&poj 2079 (凸包+旋转卡壳+求最大三角形面积)
标签:des style blog http color os io strong
原文地址:http://www.cnblogs.com/ccccnzb/p/3916542.html