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

无语了!@检查了n遍了,还是WA!!

Posted by liyanguestc at 2006-08-26 20:09:57 on Problem 2826
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <algorithm>
using namespace std;
double square(double x1,double y1, double x2,double y2,double x3,double y3);
int main()
{int n;
int x1,x2,x3,x4,y1,y2,y3,y4;
double x5;
double tmp,tmp1,tmp2;
double x,y;
double sum=0;
cin>>n;

while(n--)
{
 cin>>x1>>y1>>x2>>y2
    >>x3>>y3>>x4>>y4;

	if(y1>y2)
	{swap(y1,y2);
     swap(x1,x2);
	}
   if(y3>y4)
	{swap(y3,y4);
	swap(x3,x4);
	}
	if(((y2-y1)*(x4-x3)-(y4-y3)*(x2-x1))==0||y1==y2||y3==y4)//平行或有一个水平输出0。
	{printf("%.2f\n",0);
	continue;
	}
	tmp=(y2-y1)*(x3-x4)-(y4-y3)*(x1-x2);
	tmp1=(x1*y2-y1*x2)*(x3-x4)-(x1-x2)*(x3*y4-x4*y3);
	tmp2=(y2-y1)*(x3*y4-x4*y3)-(y4-y3)*(x1*y2-y1*x2);
	x=tmp1/tmp;
	y=tmp2/tmp;//求出直线交点
	if((x-x1)*(x-x2)>0.0001||(y-y1)*(y-y2)>0.0001)//判断点是否在线段上
	{printf("%.2f\n",0);
	continue;
	}
	if((x-x3)*(x-x4)>0.0001||(y-y3)*(y-y4)>0.0001)//判断点是否在线段上
	{printf("%.2f\n",0);
	continue;
	}
	if(y4>=y2)//求面积
	{x5=(double)((x3*y4-x4*y3)+y2*(x4-x3))/(y4-y3);
	sum=square(x5,y2,x,y,x2,y2);
	}
	else//求面积
	{x5=(double)((x1*y2-y1*x2)+y4*(x2-x1))/(y2-y1);
	sum=square(x5,y4,x,y,x4,y4);
	}

printf("%.2f\n",sum);

}

return 0;}
double square(double x1,double y1, double x2,double y2,double x3,double y3)//3点法求面积
{
double cur;
cur=(x1*y2+x3*y1+x2*y3-x3*y2-x2*y1-x1*y3)/2;
if(cur<-0.0001)
cur=-cur;
return cur;
}

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