poj 1408

#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <cmath>


using namespace std;


struct Point
{
    double x, y;
    Point () {};
    Point(double a, double b)
    {
        x = a;
        y = b;
    }
} p[4][33];
Point sta[2][33];


double Across(Point a, Point b, Point c)
{
    return (b.x - a.x)*(c.y - a.y) - (b.y - a.y)*(c.x - a.x);
}


Point GetPoint(Point a, Point b, Point c, Point d)
{
    Point temp=a;
    double t=((a.x-c.x)*(c.y-d.y)-(a.y-c.y)*(c.x-d.x))
             /((a.x-b.x)*(c.y-d.y)-(a.y-b.y)*(c.x-d.x));
    temp.x+=(b.x-a.x)*t;
    temp.y+=(b.y-a.y)*t;
    return temp;
}


double GetS(Point a, Point b, Point c, Point d)
{
    double res1 = Across(a, b, d);
    double res2 = Across(c, b, d);
    return fabs(res1)/2.0 + fabs(res2)/2.0;
}
void solve( int n)
{
    double ans = -1;
    int t = 0;


    sta[t][0] = Point(0, 1);
    for( int i = 1; i <= n; i++)
        sta[t][i] = p[1][i];
    sta[t][n+1] = Point(1, 1);


    for( int i = n; i >= 1; i--)
    {
        sta[(++t)%2][0] = Point(0,p[2][i].y);
        sta[t%2][n+1] = p[3][i];
        t%=2;
        for( int j = 1; j <= n; j++)
        {
            sta[t][j] = GetPoint(p[2][i], p[3][i], p[0][j], p[1][j]);
            double res = GetS(sta[(t+1)%2][j-1], sta[(t+1)%2][j], sta[t][j], sta[t][j-1]);
            ans = max(ans, res);
        }
         double res = GetS(sta[(t+1)%2][n],sta[(t+1)%2][n+1], sta[t][n+1], sta[t][n]);
          ans = max(ans, res);
    }


    sta[(++t)%2][0] = Point(0, 0);
    sta[t%2][n+1] = Point(1, 0);
    t%=2;
    for( int i = 1; i <= n; i++)
        sta[t][i] = p[0][i];


    for( int j = 1; j <= n; j++)
    {
      double res = GetS(sta[(t+1)%2][j-1], sta[(t+1)%2][j], sta[t][j], sta[t][j-1]);
      ans = max(ans, res);
    }
    double res = GetS(sta[(t+1)%2][n],sta[(t+1)%2][n+1], sta[t][n+1], sta[t][n]);
    ans = max(ans, res);
    printf("%.6lf\n",ans);
}
int main()
{
    int n;
    while(scanf("%d",&n) != EOF && n)
    {
        double val;


        for( int i = 0; i < 4; i++)
        {
            for( int j = 1; j <= n; j++)
            {
                scanf("%lf",&val);
                if(i == 0)
                    p[i][j] = Point(val,0);
                else if(i == 1)
                    p[i][j] = Point(val, 1);
                else if(i == 2)
                    p[i][j] = Point(0, val);
                else
                    p[i][j] = Point(1, val);
            }
        }
        solve(n);
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值