http://poj.org/problem?id=1408
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include<cstdio> 2 #include<cstring> 3 #include<cmath> 4 #include<algorithm> 5 #define maxn 1000 6 using namespace std; 7 8 const double eps=1e-8; 9 const double pi=acos(-1.0); 10 11 int cmp(double x) 12 { 13 if(fabs(x)<eps) return 0; 14 if(x>0) return 1; 15 return -1; 16 } 17 18 struct point 19 { 20 double x,y; 21 point(){} 22 point(double a,double b):x(a),y(b) {} 23 friend point operator -(const point &a,const point &b){ 24 return point(a.x-b.x,a.y-b.y); 25 } 26 friend point operator * (const point &a,const double b) 27 { 28 return point (a.x*b,a.y*b); 29 } 30 friend point operator / (const point &a,const double b) 31 { 32 return point(a.x/b,a.y/b); 33 } 34 }; 35 struct line 36 { 37 point a,b; 38 line(){} 39 line(point x,point y):a(x),b(y){} 40 }; 41 inline double sqr(double x) 42 { 43 return x*x; 44 } 45 double det(point a,point b) 46 { 47 return a.x*b.y-a.y*b.x; 48 } 49 double dot(point a,point b) 50 { 51 return a.x*b.x+a.y*b.y; 52 } 53 double dist(point a,point b) 54 { 55 return sqrt(sqr(a.x-b.x)+sqr(a.y-b.y)); 56 } 57 double area(point a[]) 58 { 59 double sum=0; 60 a[4]=a[0]; 61 for(int i=0; i<4; i++) 62 { 63 sum+=det(a[i+1],a[i]); 64 } 65 return sum/2; 66 } 67 68 bool parallel (line a,line b) 69 { 70 return !cmp(det(a.a-a.b,b.a-b.b)); 71 } 72 73 bool line_make_point(line a,line b,point &res) 74 { 75 if(parallel(a,b)) return false; 76 double s1=det(a.a-b.a,b.b-b.a); 77 double s2=det(a.b-b.a,b.b-b.a); 78 res=(a.b*s1-a.a*s2)/(s1-s2); 79 return true; 80 } 81 82 int main() 83 { 84 int n; 85 double a[maxn],b[maxn],c[maxn],d[maxn]; 86 point m[110][110]; 87 line l[110][110]; 88 while(scanf("%d",&n)&&n){ 89 double max1=eps; 90 for(int i=1; i<=n; i++){ 91 scanf("%lf",&a[i]); 92 m[0][i].x=a[i]; 93 m[0][i].y=0; 94 95 } 96 m[0][0].x=0; 97 m[0][0].y=0; 98 m[0][n+1].x=1; 99 m[0][n+1].y=0; 100 for(int j=1; j<=n; j++){ 101 scanf("%lf",&b[j]); 102 m[n+1][j].x=b[j]; 103 m[n+1][j].y=1; 104 } 105 m[n+1][0].x=0; 106 m[n+1][0].y=1; 107 m[n+1][n+1].x=1; 108 m[n+1][n+1].y=1; 109 for(int k=1; k<=n; k++){ 110 scanf("%lf",&c[k]); 111 m[k][0].y=c[k]; 112 m[k][0].x=0; 113 } 114 for(int t=1 ; t<=n; t++){ 115 scanf("%lf",&d[t]); 116 m[t][n+1].x=1; 117 m[t][n+1].y=d[t]; 118 } 119 for(int i=1; i<=n; i++) 120 { 121 l[i][0].a=m[0][i]; 122 l[i][0].b=m[n+1][i]; 123 } 124 for(int i=1; i<=n; i++) 125 { 126 l[0][i].a=m[i][0]; 127 l[0][i].b=m[i][n+1]; 128 } 129 for(int i=1; i<=n; i++) 130 { 131 for(int j=1; j<=n; j++) 132 { 133 point res; 134 line_make_point(l[0][i],l[j][0],res); 135 m[i][j]=res; 136 } 137 } 138 for(int i=0; i<=n+1; i++) 139 { 140 for(int j=0; j<=n+1; j++) 141 { 142 point s[110]; 143 s[3]=m[i-1][j-1]; 144 s[2]=m[i-1][j]; 145 s[1]=m[i][j]; 146 s[0]=m[i][j-1]; 147 max1=max(max1,area(s)); 148 //printf("%.6lf ",area(s)); 149 } 150 //printf(" "); 151 } 152 printf("%.6lf ",max1); 153 } 154 return 0; 155 }