您的位置:首页 > 其它

poj 1408 Fishnet

2016-11-02 19:12 176 查看
Fishnet

Time Limit: 1000MSMemory Limit: 10000K
Total Submissions: 2193Accepted: 1385
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 this island 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 at 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 are n pegs on each edge, and thus there are 4n pegs in total. The positions of pegs are represented by their (x,y)-coordinates.
Those of an example case with n=2 are depicted in figures below. The position of the ith peg on the bottom edge is represented by (ai,0). That on the top edge, on the left edge and on the right edge are represented by (bi,1), (0,ci) and (1,di), respectively.
The long thread is cut into 2n threads with appropriate lengths. The threads are strained between (ai,0) and (bi,1),and between (0,ci) and (1,di) (i=1,...,n).

You should write a program that reports the size of the largest mesh among the (n+1)2 meshes of the fishnet made by fixing the threads at the pegs. You may assume that the thread he found is long enough to make the fishnet and the wood-frame is thin enough
for neglecting 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 is given in the following format.

n

a1 a2 ... an

b1 b2 ... bn

c1 c2 ... cn

d1 d2 ... dn

you may assume 0 < n <= 30, 0 < ai,bi,ci,di < 1
Output

For each sub-problem, the size of the largest mesh should be printed followed by a new line. Each value should be represented by 6 digits after the decimal point, and it may not have an error greater than 0.000001.
Sample Input
2
0.2000000 0.6000000
0.3000000 0.8000000
0.1000000 0.5000000
0.5000000 0.6000000
2
0.3333330 0.6666670
0.3333330 0.6666670
0.3333330 0.6666670
0.3333330 0.6666670
4
0.2000000 0.4000000 0.6000000 0.8000000
0.1000000 0.5000000 0.6000000 0.9000000
0.2000000 0.4000000 0.6000000 0.8000000
0.1000000 0.5000000 0.6000000 0.9000000
2
0.5138701 0.9476283
0.1717362 0.1757412
0.3086521 0.7022313
0.2264312 0.5345343
1
0.4000000
0.6000000
0.3000000
0.5000000
0

Sample Output
0.215657
0.111112
0.078923
0.279223
0.348958


题意:
一个1X1的正方形,每条边上有n个不同的点(不包括顶点),并给出它们的坐标。现在把对边相对应的点相连,将正方形分割成(n+1)*(n+1)个小四边形。问最大的四边形的面积是多少。

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std;

struct node
{
double x, y;
}a[102][102];

double fas(double sum)
{
return sum >= 0.0 ? sum : -sum;
}

double cross(node x, node y, node z, node h)
{
return (y.x-x.x)*(h.y-z.y)-(h.x-z.x)*(y.y-x.y);
}
node Point(node x, node y, node z, node h)
{
node temp;//x,y直线  z,h直线
double area1 = cross(x, y, x, z);
double area2 = cross(x, y, x, h);
temp.x = (area2*z.x-area1*h.x)/(area2-area1);
temp.y = (area2*z.y-area1*h.y)/(area2-area1);
return temp;//交点
}
double Sum(node x, node y, node z, node h)
{   //四边形的面积,四个点
double sum1 = cross(x, y, x, z);
double sum2 = cross(h, y, h, z);
sum1 = fas(sum1)/2.0;
sum2 = fas(sum2)/2.0;
return sum1+sum2;
}

int main()
{
int i, j, n;
double m;
while ( ~scanf ( "%d", &n )&&n != 0 )
{
a[0][0].x =0.0;
a[0][0].y =0.0;
a[0][n+1].x=0.0;
a[0][n+1].y=1.0;
a[n+1][0].x=1.0;
a[n+1][0].y=0.0;
a[n+1][n+1].x=1.0;
a[n+1][n+1].y=1.0;
for ( j = 0;j < 4; j++ )
{
for ( i = 1;i <= n; i++ )
{
if ( j == 0 )
{
scanf ( "%lf", &a[i][0].x );
a[i][0].y = 0;
}
else if ( j == 1 )
{
scanf ( "%lf", &a[i][n+1].x );
a[i][n+1].y = 1.0;
}
else if ( j == 2 )
{
scanf ( "%lf", &a[0][i].y );
a[0][i].x = 0;
}
else if ( j == 3 )
{
scanf ( "%lf",  &a[n+1][i].y );
a[n+1][i].x = 1.0;
}
}
}
for ( i = 1;i <= n; i++ )
{
for ( j = 1;j <= n; j++ )
{
a[i][j] = Point(a[i][0], a[i][n+1], a[0][j] , a[n+1][j]);
}
}
double sum = 0, sum1;
for ( i = 0;i <= n; i++ )
{
for ( j = 0;j <= n; j++ )
{
sum1 = Sum(a[i][j], a[i+1][j], a[i][j+1], a[i+1][j+1]);
if ( sum < sum1 )
sum = sum1;
}
}
printf ( "%.6f\n", sum );
}
}


代码菜鸟,如有错误,请多包涵!!!
如有帮助记得支持我一下,谢谢!!!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: