poj1408--Fishnet(求多边形面积)

Fishnet

Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d
& %I64u

Submit Status

Appoint description: 
System Crawler  (2013-02-19)

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

题意很简单,在1*1的正方形块中每条边有n个点,对应边的对应点连线,将正方形分割成(n+1)*(n+1)个小正方形,求出小正方形中的最大的面积。

先储存下每个点的坐标,然后用叉积计算出各个小正方形的面积,找出最大值。

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std ;
#define eps 1e-8
struct node
{
    double x , y ;
} p[40][40];
double a[40] , b[40] , c[40] , d[40] ;
node f(node a1,node a2,node b1,node b2)
{
    node q = a1 ;
    double t = ( (a1.x-b1.x)*(b1.y-b2.y) - (a1.y-b1.y)*(b1.x-b2.x) ) / ( (a1.x-a2.x)*(b1.y-b2.y) - ( a1.y-a2.y )*(b1.x-b2.x) ) ;
    q.x += (a2.x-a1.x)*t ;
    q.y += ( a2.y-a1.y )*t ;
    return q ;
}
int main()
{
    int n , i , j ;
    double k , max1 , ans ;
    while( scanf("%d", &n) && n )
    {
        p[0][0].x = p[0][0].y = 0.0 ;
        for(i = 1 ; i <= n ; i++)
        {
            scanf("%lf", &a[i]) ;
            p[0][i].x = a[i] ;
            p[0][i].y = 0.0 ;
        }
        p[0][n+1].x = 1.0 ;
        p[0][n+1].y = 0.0 ;
        p[n+1][0].x = 0 ;
        p[n+1][0].y = 1.0 ;
        for(i = 1 ; i <= n ; i++)
        {
            scanf("%lf", &b[i]) ;
            p[n+1][i].x = b[i] ;
            p[n+1][i].y = 1.0 ;
        }
        p[n+1][n+1].x = p[n+1][n+1].y = 1.0 ;
        for(i = 1 ; i <= n ; i++)
        {
            scanf("%lf", &c[i]) ;
            p[i][0].x = 0.0 ;
            p[i][0].y = c[i] ;
        }
        for(i = 1 ; i <= n ; i++)
        {
            scanf("%lf", &d[i]) ;
            p[i][n+1].x = 1.0 ;
            p[i][n+1].y = d[i] ;
        }
        for(i = 1 ; i <= n ; i++)
            for(j = 1 ; j <= n ; j++)
            {
                if( fabs( c[i]-d[i] ) < eps && fabs( b[j]-a[j] ) < eps )
                {
                    p[i][j].x = a[j] ;
                    p[i][j].y = c[i] ;
                }
                else if( fabs( c[i]-d[i] ) < eps && fabs( b[j]-a[j] ) > eps )
                {
                    p[i][j].x = c[i]*(b[j]-a[j]) + a[j] ;
                    p[i][j].y = c[i] ;
                }
                else if( fabs( c[i]-d[i] ) > eps && fabs( b[j]-a[j] ) < eps )
                {
                    p[i][j].x = a[j] ;
                    p[i][j].y = a[j]*(d[i]-c[i]) + c[i] ;
                }
                else
                {
                    p[i][j] = f(p[0][j],p[n+1][j],p[i][0],p[i][n+1]) ;
                }
            }
        node s1 , e1 , s2 , e2 ;
        max1 = 0 ;
        for(i = 0 ; i <= n ; i++)
            for(j = 0 ; j <= n ; j++)
            {
                s1.x = p[i][j+1].x - p[i][j].x ; s1.y = p[i][j+1].y - p[i][j].y ;
                e1.x = p[i+1][j+1].x - p[i][j+1].x ; e1.y = p[i+1][j+1].y - p[i][j+1].y ;
                s2.x = p[i+1][j].x - p[i][j].x ; s2.y = p[i+1][j].y - p[i][j].y ;
                e2.x = p[i+1][j+1].x - p[i+1][j].x ; e2.y = p[i+1][j+1].y - p[i+1][j].y ;
                ans = ( fabs(s1.x*e1.y-s1.y*e1.x)/2.0 + fabs(s2.x*e2.y-s2.y*e2.x)/2.0 ) ;
                max1 = max(max1,ans) ;
            }
        printf("%.6lf\n", max1) ;
    }
    return 0;
}

时间: 2024-10-16 12:21:50

poj1408--Fishnet(求多边形面积)的相关文章

poj1408——叉积求多边形面积

poj1408——叉积求多边形面积 Fishnet Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 1853   Accepted: 1185 Description A fisherman named Etadokah awoke in a very small island. He could see calm, beautiful and blue sea around the island. The previou

三角剖分求多边形面积的交 HDU3060

1 //三角剖分求多边形面积的交 HDU3060 2 3 #include <iostream> 4 #include <cstdio> 5 #include <cstring> 6 #include <stack> 7 #include <queue> 8 #include <cmath> 9 #include <algorithm> 10 using namespace std; 11 12 const int max

poj1265--Area(求多边形面积+匹克定理)

Area Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5150   Accepted: 2308 Description Being well known for its highly innovative products, Merck would definitely be a good target for industrial espionage. To protect its brand-new resear

hdu 2036 求多边形面积 (凸、凹多边形)

<题目链接> Problem Description " 改革春风吹满地,不会AC没关系;实在不行回老家,还有一亩三分地.谢谢!(乐队奏乐)" 话说部分学生心态极好,每天就知道游戏,这次考试如此简单的题目,也是云里雾里,而且,还竟然来这么几句打油诗.好呀,老师的责任就是帮你解决问题,既然想种田,那就分你一块.这块田位于浙江省温州市苍南县灵溪镇林家铺子村,多边形形状的一块地,原本是linle 的,现在就准备送给你了.不过,任何事情都没有那么简单,你必须首先告诉我这块地到底有多

poj 1654 Area(求多边形面积)

题意:从原点出发向八个方向走,所给数字串每个数字代表一个方向,终点与原点连线,求所得多边形面积: 思路:(性质)共起点的两向量叉积的一半为两向量围成三角形的面积.以此计算每条边首尾两个向量的叉积,求和,除二: #include<cstdio> #include<iostream> #include<cstring> #include<cmath> #include<algorithm> using namespace std; const dou

Area - POJ 1654(求多边形面积)

题目大意:从原点开始,1-4分别代表,向右下走,向右走,向右上走,向下走,5代表回到原点,6-9代表,向上走,向左下走,向左走,向左上走.求出最后的多边形面积. 分析:这个多边形面积很明显是不规则的,可以使用向量积直接求出来面积即可. 代码如下: ------------------------------------------------------------------------------------------------------------------------------

HDOJ-2036-改革春风吹满地 叉积求多边形面积

改革春风吹满地 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 22754 Accepted Submission(s): 11772 Problem Description " 改革春风吹满地, 不会AC没关系; 实在不行回老家, 还有一亩三分地. 谢谢!(乐队奏乐)" 话说部分学生心态极好,每天就知道游戏,这次考试如此简单的题目

HDU 2036 改革春风吹满地 (求多边形面积)

传送门: 改革春风吹满地 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 42663    Accepted Submission(s): 21856 Problem Description " 改革春风吹满地,不会AC没关系;实在不行回老家,还有一亩三分地.谢谢!(乐队奏乐)" 话说部分学生心态极好,每天就知道游戏,这次考试如

求多边形面积

杭电2036 开始想到用三边形法求面积 三角形海伦面积公式如下: 假设在平面内,有一个三角形,边长分别为a.b.c,三角形的面积S可由以下公式求得: S=sqrt(p(p-a)(p-b)(p-c)) 公式中的p为半周长: p=(a+b+c)/2 #include <stdio.h>#include <math.h>double c(double i,double j,double x,double y,double m,double n){ double s,p,a,b,c; a=

poj 3348 Cows 凸包 求多边形面积 计算几何 难度:0 Source:CCC207

Cows Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7038   Accepted: 3242 Description Your friend to the south is interested in building fences and turning plowshares into swords. In order to help with his overseas adventure, they are f