http://poj.org/problem?id=1408
求分割出来的最大的面积 求交点坐标 枚举n*n个面积
对这题相当无语 实在不知道精度该加哪 加了精度一直WA 去掉就AC了。
#include <iostream>
#include<cstdio>
#include<cstring>
#include<stdlib.h>
#include<cmath>
#define eps 1e-8
using namespace std;
typedef struct node
{
double x,y;
}point;
point p[50][50];
int n;
void init()
{
int i;
p[n+2][1].x = 0;
p[n+2][1].y = 1;
p[n+2][n+2].x = 1;
p[n+2][n+2].y = 1;
p[1][1].x = 0;
p[1][1].y = 0;
p[1][n+2].x = 1;
p[1][n+2].y = 0;
for(i = 2 ; i <= n+1 ;i++)
{
p[1][i].y = 0;
cin>>p[1][i].x;
}
for(i = 2 ; i <= n+1 ; i++)
{
p[n+2][i].y = 1;
cin>>p[n+2][i].x;
}
for(i = 2 ; i <= n+1 ;i++)
{
p[i][1].x = 0;
cin>>p[i][1].y;
}
for(i = 2 ; i <= n+1 ;i++)
{
p[i][n+2].x = 1;
cin>>p[i][n+2].y;
}
}
point intersection(point a,point b,point c,point d)
{
point pp = 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));
pp.x+=(b.x-a.x)*t;
pp.y+=(b.y-a.y)*t;
return pp;
}
double cross(point a,point b)
{
return a.x*b.y-a.y*b.x;
}
int main()
{
int i,j;
while(cin>>n)
{
if(n==0)
break;
init();
for(i = 2 ; i <= n+1 ; i++)
{
for(j = 2 ; j <= n+1 ; j++)
p[j][i] = intersection(p[1][i],p[n+2][i],p[j][1],p[j][n+2]);
}
double ma = 0.0;
for(i = 1 ; i <= n+1 ; i++)
{
for(j = 1 ; j <= n+1 ; j++)
{
double s = cross(p[i][j],p[i][j+1])+cross(p[i][j+1],p[i+1][j+1])+cross(p[i+1][j+1],p[i+1][j])+cross(p[i+1][j],p[i][j]);
s = s/2;
if(s>ma)
ma = s;
}
}
printf("%.6lf\n",ma);
}
return 0;
}