Fishnet
Time Limit: 1000MS |
|
Memory Limit: 10000K |
Total Submissions: 1788 |
|
Accepted: 1144 |
Description
A fisherman named Etadokah awoke in a very small island. He could see calm, beautiful and blue sea around the island. The previous night he had encountered a terrible storm and had reached this uninhabited island. Some wrecks of his ship were spread around him. He found a square wood-frame and a long thread among the wrecks. He had to survive in the until someone came and saved him.
In order to catch fish, he began to make a kind of fishnet by cutting the long thread into short threads and fixing them a T pegs on the square wood-frame. He wanted to know the sizes of the meshes of the fishnet to see whether he could catch small fish as well as large ones.
The wood frame is perfectly square with four thin edges on meter long:a bottom edge, a top edge, a left edge, and a right Edge. There is n pegs on each edge, and thus there is 4n pegs in total. The positions of pegs is represented by their (x, y)-coordinates. Those of an example case with n=2 is depicted in figures below. The position of the ith peg on the bottom edge are represented by (ai,0). That on the top edge, the left edge and on the right edge is represented by (bi,1), (0,CI) and (1,di), respectively. The long thread is cut to 2n threads with appropriate lengths. The threads is strained between (ai,0) and (bi,1), and between (0,ci) and (1,di) (I=1,..., N).
You should write a program this reports the size of the largest mesh among the (n+1) 2 meshes of the fishnet made by fixing The threads at the pegs. Assume that the thread he found is a long enough to make the fishnet and the wood-frame are thin enough for neglectin g its thickness.
Input
The input consists of multiple sub-problems followed by a line containing a zero that indicates the end of input. Each sub-problem are given in the following format.
N
A1 A2 ... an
B1 B2 ... Bn
C1 C2 ... cn
D1 D2 ... dn
Assume 0 < n <= 0 < Ai,bi,ci,di < 1
Output
For each sub-problem, the size of the largest mesh should is printed followed by a new line. Each of the value should is represented by 6 digits after the decimal point, and it is not having an error greater than 0.000001.
Sample Input
20.2000000 0.60000000.3000000 0.80000000.1000000 0.50000000.5000000 0.600000020.3333330 0.66666700.3333330 0.66666700.3333330 0.66666700.3333330 0.666667040.2000000 0.4000000 0.6000000 0.80000000.1000000 0.5000000 0.6000000 0.90000000.2000000 0.4000000 0.6000000 0.80000000.1000000 0.5000000 0.6000000 0.900000020.5138701 0.94762830.1717362 0.17574120.3086521 0.70223130.2264312 0.534534310.40000000.60000000.30000000.50000000
Sample Output
0.2156570.1111120.0789230.2792230.348958
Test instructions: The picture on the question is obvious. Idea: The line of intersection (the line on the edge of the calculation), the resulting 4 points to calculate the area.
#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <vector > #include <algorithm>using namespace std; #define REP (_,A,B) for (int _ = (a); _ < (b); _++) #define SZ (s) (int) ((s). Size ()) typedef long LONG ll;const double EPS = 1e-10;const int maxn = 50;int n;struct point{double x, y; Point (double x=0.0,double y = 0.0): x (x), Y (y) {}}; Point Vp[maxn];typedef point vector;struct Line {point P; Vector v;double ang; Line () {}line (Point P,vector v):P (P), V (v) {ang = atan2 (v.y,v.x);} BOOL operator < (const line&l) Const{return ang < L.ang;}}; Line LX[MAXN],LY[MAXN]; Vector operator + (vector a,vector B) {return vector (A.X+B.X,A.Y+B.Y);} Vector operator-(vector a,vector B) {return vector (A.X-B.X,A.Y-B.Y);} Vector operator * (vector a,double p) {return vector (a.x*p,a.y*p);} Vector operator/(vector a,double p) {return vector (a.x/p,a.y/p);} int dcmp (double x) {if (Fabs (x) < EPS) return 0;else return x < 0? -1:1;} BOOL operator < (const POint &a,const point &b) {return dcmp (a.x-b.x) <0 | | dcmp (a.x-b.x) ==0&&dcmp (A.Y-B.Y) <0;} BOOL operator = = (Const point &a,const point &b) {return dcmp (a.x-b.x) ==0&& dcmp (A.Y-B.Y) ==0;} Double Dot (Vector a,vector B) {return a.x*b.x+a.y*b.y;} Double Length (Vector A) {return sqrt (Dot (a,a));} Double Angle (Vector a,vector B) {return ACOs (Dot (b)/length (A)/length (b)); Double Cross (Vector a,vector B) {return a.x*b.y-a.y*b.x;} Vector Rotate (vector a,double rad) {return vector (A.x*cos (RAD)-a.y*sin (RAD), A.x*sin (RAD) +a.y*cos (RAD));} Vector Normal (vector a) {double L = Length (a); return vector (-a.y/l,a.x/l);} BOOL Onsegment (Point p,point a1,point A2) {return dcmp (Cross (a1-p,a2-p)) = = 0 && dcmp (Dot (a1-p,a2-p)) < 0;} Point Getintersection [line A,line b] {Vector u = a.p-b.p;double t = Cross (B.V,U)/Cross (A.V,B.V); return a.p+a.v*t;} int Convexhull (point* p,int n,point *ch) {sort (p,p+n); int m = 0;for (int i = 0; i < n; i++) {while (M > 1 && DC MP (Cross (ch[m-1]-ch[m-2],p[i]-ch[m-2]) <= 0) m--;ch[m++] = P[i]; }int k = m;for (int i = n-2; I >= 0; i--) {while (M > K && dcmp (Cross (ch[m-1]-ch[m-2],p[i]-ch[m-2))) <= 0) m --;ch[m++] = P[i];} if (n > 1) m--;return m;} Double a[maxn];void input () {double T; REP (i,0,n) scanf ("%lf", &a[i]); Lx[0] = line (point (0,1.0), Vector (0,-1.0)); REP (i,0,n) {scanf ("%lf", &t); Lx[i+1] = line (point (t,1.0), Vector (a[i]-t,-1.0));} Lx[n+1] = line (point (1.0,1.0), Vector (0,-1.0)); Ly[0] = line (point (1.0,0), Vector ( -1.0,0)); REP (i,0,n) scanf ("%lf", &a[i]); REP (i,0,n) {scanf ("%lf", &t); Ly[i+1] = line (point (1.0,t), Vector ( -1.0,A[I]-T));} Ly[n+1] = line (point (1.0,1.0), Vector ( -1.0,0));} void Solve () {double ans = 0; REP (i,1,n+2) {point a,b,c,d; REP (j,1,n+2) {a = Getintersection (lx[i-1],ly[j-1]);//cout<<a.x<< "" <<a.y<<endl;b = Getintersection (lx[i],ly[j-1]);//cout<<b.x<< "" <<a.y<<endl;c = GetIntersection (LX[i],LY[j ]);d = Getintersection (Lx[i-1],ly[j]);d ouble area = 0;area= Fabs (cross (b)/2+cross (b,c)/2+cross (c,d)/2+cross (d,a)/2); ans = max (Area,ans);}} printf ("%.6f\n", ans);} int main () {while (~SCANF ("%d", &n) && N) {input (); Solve ();} return 0;}