Fishnet--计算几何

Fishnet
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 2132 Accepted: 1343

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. 

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

题目链接:http://poj.org/problem?id=1408


poj初级训练计划我的最后一题,我的天,前两天看了题解并没有看懂,然后就放下了,然后就一直放到了最后,我的天,今天又想了半天,然而我太渣。。。。我很奇怪都已经到小数点后六位了,但是他并没有涉及到精度问题,我的代码你会惊讶的发现和网上的大神差不多,不过我已经懂了思路,果然,大神就是大神,口中的水题我并不会做。。。。


链上大神的博客吧,讲的太仔细了。

http://blog.csdn.net/lyy289065406/article/details/6648592


我的天,懂了之后才发现原来这个题这么简单,但是那个用叉积和定比分点来求交点的那里并不是很懂。。。。上篇计算几何的博客就没懂,问了菊苣们,然而菊苣们并没有给我讲懂。。。。


代码:

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
struct node
{
    double x,y;
};
double chacheng(double x1,double y1,double x2,double y2)//计算叉积
{
    return x1*y2-x2*y1;
}
double cross(struct node A,struct node B,struct node C,struct node D)//叉积的板子
{
    return chacheng(B.x-A.x,B.y-A.y,D.x-C.x,D.y-C.y);
}
double xx,yy;
void intersection(struct node A,struct node B,struct node C,struct node D)//利用叉积和定比分点求交点
{//然而这个函数只是会用板子,并不懂原理,还要继续研究啊
    double area1=cross(A,B,A,C);
    double area2=cross(A,B,A,D);
    xx=(area2*C.x-area1*D.x)/(area2-area1);
    yy=(area2*C.y-area1*D.y)/(area2-area1);
    return ;
}
double area(struct node A,struct node B,struct node C,struct node D)//计算面积
{
    double s1=fabs(0.5*cross(A,B,A,C));//一定要有绝对值,因为叉积计算的面积可能会有负值
    double s2=fabs(0.5*cross(A,B,A,D));
    return s1+s2;
}
struct node xin[1000][1000];
int main()
{
    int i,j;
    int n;
    while(~scanf("%d",&n)&&n)
    {
        xin[0][0].x=0.0;//下边
        xin[0][0].y=0.0;
        for(i=1;i<=n;i++)
        {
            scanf("%lf",&xin[0][i].x);
            xin[0][i].y=0.0;
        }
        xin[0][n+1].x=1.0;
        xin[0][n+1].y=0.0;
        xin[n+1][0].x=0.0;//上边
        xin[n+1][0].y=1.0;
        for(i=1;i<=n;i++)
        {
            scanf("%lf",&xin[n+1][i].x);
            xin[n+1][i].y=1.0;
        }
        xin[n+1][n+1].x=1.0;
        xin[n+1][n+1].y=1.0;
        for(i=1;i<=n;i++)//左边
        {
            scanf("%lf",&xin[i][0].y);
            xin[i][0].x=0.0;
        }
        for(i=1;i<=n;i++)//右边
        {
            scanf("%lf",&xin[i][n+1].y);
            xin[i][n+1].x=1.0;
        }
        for(j=1;j<=n;j++)//计算交点坐标
        {
            for(i=1;i<=n;i++)
            {
                intersection(xin[0][j],xin[n+1][j],xin[i][0],xin[i][n+1]);
                xin[i][j].x=xx;
                xin[i][j].y=yy;
            }
        }
        double maxc=0.0;
        for(i=1;i<=n+1;i++)//计算面积
        {
            for(j=1;j<=n+1;j++)
            {
                double temp=area(xin[i-1][j-1],xin[i][j],xin[i][j-1],xin[i-1][j]);
                if(maxc<temp)
                    maxc=temp;
            }
        }
        printf("%.6f\n",maxc);
    }
    return 0;
}



我的poj初级训练计划上的另一个计算方法的那个题到现在没有搞懂。。。好难啊QAQ    TAT|||


目录 ㈠ 点的基本运算 1. 平面上两点之间距离 1 2. 判断两点是否重合 1 3. 矢量叉乘 1 4. 矢量点乘 2 5. 判断点是否在线段上 2 6. 求一点饶某点旋转后的坐标 2 7. 求矢量夹角 2 ㈡ 线段及直线的基本运算 1. 点与线段的关系 3 2. 求点到线段所在直线垂线的垂足 4 3. 点到线段的最近点 4 4. 点到线段所在直线的距离 4 5. 点到折线集的最近距离 4 6. 判断圆是否在多边形内 5 7. 求矢量夹角余弦 5 8. 求线段之间的夹角 5 9. 判断线段是否相交 6 10.判断线段是否相交但不交在端点处 6 11.求线段所在直线的方程 6 12.求直线的斜率 7 13.求直线的倾斜角 7 14.求点关于某直线的对称点 7 15.判断两条直线是否相交及求直线交点 7 16.判断线段是否相交,如果相交返回交点 7 ㈢ 多边形常用算法模块 1. 判断多边形是否简单多边形 8 2. 检查多边形顶点的凸凹性 9 3. 判断多边形是否凸多边形 9 4. 求多边形面积 9 5. 判断多边形顶点的排列方向,方法一 10 6. 判断多边形顶点的排列方向,方法二 10 7. 射线法判断点是否在多边形内 10 8. 判断点是否在凸多边形内 11 9. 寻找点集的graham算法 12 10.寻找点集凸包的卷包裹法 13 11.判断线段是否在多边形内 14 12.求简单多边形的重心 15 13.求凸多边形的重心 17 14.求肯定在给定多边形内的一个点 17 15.求从多边形外一点出发到该多边形的切线 18 16.判断多边形的核是否存在 19 ㈣ 圆的基本运算 1 .点是否在圆内 20 2 .求不共线的三点所确定的圆 21 ㈤ 矩形的基本运算 1.已知矩形三点坐标,求第4点坐标 22 ㈥ 常用算法的描述 22 ㈦ 补充 1.两圆关系: 24 2.判断圆是否在矩形内: 24 3.点到平面的距离: 25 4.点是否在直线同侧: 25 5.镜面反射线: 25 6.矩形包含: 26 7.两圆交点: 27 8.两圆公共面积: 28 9. 圆和直线关系: 29 10. 内切圆: 30 11. 求切点: 31 12. 线段的左右旋: 31 13.公式: 32
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值