Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

改成stdio就对了,求解!!!!!!!

Posted by Mikucon at 2012-07-11 12:23:00 on Problem 1408
In Reply To:全过了还WA附代码 Posted by:Mikucon at 2012-07-11 12:13:16
#include <stdio.h>
#include <cmath>
int n;
double a[111],b[111],c[111],d[111];
struct point
{
	double x,y;
};
point p1,p2,p3,p4,x1,x2,x3,x4;
double ans;
#define eps 1.0e-8
point intersect(point a,point b,point c,point d)
{
	point p;
	if(abs(c.x-d.x)>eps)
	{
		double e1=(b.y-a.y)/(b.x-a.x)-(c.y-d.y)/(c.x-d.x);
		double e2=c.y-b.y+b.x*(b.y-a.y)/(b.x-a.x)-c.x*(c.y-d.y)/(c.x-d.x);
		p.x=e2/e1;
		p.y=(b.y-a.y)/(b.x-a.x)*(p.x-b.x)+b.y;
	}
	else{
		p.x=c.x;
		p.y=(b.y-a.y)/(b.x-a.x)*(p.x-b.x)+b.y;
	}
	return p;
}
double sur(point a,point b,point c,point d)
{
	double s1=0.5*abs((p2.x-p1.x)*(p4.y-p1.y)-(p2.y-p1.y)*(p4.x-p1.x));
	double s2=0.5*abs((p3.x-p2.x)*(p4.y-p3.y)-(p3.y-p2.y)*(p4.x-p3.x));
	return s1+s2;
}
double max(double a,double b)
{
	if(a>b) return a;
	else return b;
}
int main()
{
	while(scanf("%d",&n)!=EOF)
	{
		if(n==0) break;
		for(int i=1;i<=n;i++) scanf("%lf",&a[i]);
		for(int i=1;i<=n;i++) scanf("%lf",&b[i]);
		for(int i=1;i<=n;i++) scanf("%lf",&c[i]);
		for(int i=1;i<=n;i++) scanf("%lf",&d[i]);
		c[0]=a[0]=b[0]=d[0]=0;
		a[n+1]=b[n+1]=c[n+1]=d[n+1]=1;
		ans=0;
		for(int i=1;i<=n+1;i++)
			for(int j=1;j<=n+1;j++)
			{
				x1.x=0;x1.y=c[i-1];x2.x=1;x2.y=d[i-1];
				x3.x=b[j-1];x3.y=1;x4.x=a[j-1];x4.y=0;
				p1=intersect(x1,x2,x3,x4);
				x1.x=0;x1.y=c[i];	x2.x=1;x2.y=d[i];
				x3.x=b[j-1];x3.y=1;x4.x=a[j-1];x4.y=0;
				p2=intersect(x1,x2,x3,x4);
				x1.x=0;x1.y=c[i];	x2.x=1;x2.y=d[i];
				x3.x=b[j];x3.y=1;x4.x=a[j];x4.y=0;
				p3=intersect(x1,x2,x3,x4);
				x1.x=0;x1.y=c[i-1];	x2.x=1;x2.y=d[i-1];
				x3.x=b[j];x3.y=1;x4.x=a[j];x4.y=0;
				p4=intersect(x1,x2,x3,x4);
				ans=max(ans,sur(p1,p2,p3,p4));
			}
			printf("%.6lf\n",ans);
	}
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator