| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
水水过#include <iostream>
#include <stdio.h>
#include <cmath>
using namespace std;
struct pt{
double x,y;
};
double a[233], b[233], c[233], d[233];
int n;
void initX(double *x){
for(int i = 1; i <= n; i++){
scanf("%lf", &x[i]);
}
}
bool init(){
scanf("%d", &n);
if(!n) return 0;
a[0] = b[0] = c[0] = d[0] = 0;
initX(a);
initX(b);
initX(c);
initX(d);
a[n+1] = b[n+1] = c[n+1] = d[n+1] = 1;
return 1;
}
double getArea(pt& p1, pt& p2, pt& p3){
return 0.5*abs(p1.x*(p2.y-p3.y)+p2.x*(p3.y-p1.y)+p3.x*(p1.y-p2.y));
}
pt getInt(int i, int j){
pt p;
double fm = 1-(b[i]-a[i])*(d[j]-c[j]);
p.x = (c[j]*b[i]+(1-c[j])*a[i])/fm;
p.y = ((1-a[i])*c[j]+a[i]*d[j])/fm;
return p;
}
double getArea(int i, int j){
pt p1 = getInt(i,j), p2 = getInt(i,j+1), p3 = getInt(i+1,j+1), p4 = getInt(i+1,j);
return getArea(p1,p2,p3)+getArea(p3,p4,p1);
}
double getMax(){
double mx = 0.0;
for(int i = 0; i <= n; i++){
for(int j = 0; j <= n; j++){
double tmp = getArea(i,j);
if(tmp > mx) mx = tmp;
}
}
return mx;
}
int main() {
while(init()){
printf("%.6lf\n", getMax());
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator