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

求助啊~大神来改错

Posted by 11408129 at 2012-07-30 10:51:07 on Problem 1410
#include <iostream>
using namespace std;
typedef struct Point
{
	double x,y;
}Point;

Point p[7],l[3];

double max(double a,double b)
{
	return a>=b?a:b;
}

double min(double a,double b)
{
	return a<=b?a:b;
}

double multi(Point p1,Point p2,Point p0)  
{
    return (p1.x - p0.x)*(p2.y - p0.y) - (p2.x - p0.x)*(p1.y - p0.y);
}

bool is_cross(Point p1,Point p2,Point p3,Point p4)
{   return  max(p1.x,p2.x)>=min(p3.x,p4.x)
         && max(p3.x,p4.x)>=min(p1.x,p2.x)
         && max(p1.y,p2.y)>=min(p3.y,p4.y)
         && max(p3.y,p4.y)>=min(p1.y,p2.y)
         && multi(p3,p2,p1)*multi(p2,p4,p1)>=0
         && multi(p1,p4,p3)*multi(p4,p2,p3)>=0;
}

int main()
{
	int n;
	while(n--)
	{
		cin>>l[1].x>>l[1].y>>l[2].x>>l[2].y>>p[5].x>>p[5].y>>p[6].x>>p[6].y;
		p[1].x=p[5].x<=p[6].x?p[5].x:p[6].x;
		p[1].y=p[5].y>=p[6].y?p[5].y:p[6].y;
		p[2].x=p[5].x>=p[6].x?p[5].x:p[6].x;
		p[2].y=p[5].y<=p[6].y?p[5].x:p[6].y;
		p[3].x=p[1].x;p[3].y=p[2].y;p[4].x=p[2].x;p[4].y=p[1].y;
		if(is_cross(l[1],l[2],p[1],p[4])||is_cross(l[1],l[2],p[1],p[3])||
		   is_cross(l[1],l[2],p[2],p[3])||is_cross(l[1],l[2],p[4],p[2]))
		     cout<<"T"<<endl;
        else if(l[1].x>=p[1].x&&l[1].x<=p[2].x&&l[2].x>=p[1].x&&l[2].x<=p[2].x&&
		        l[1].y>=p[1].y&&l[1].y<=p[2].y&&l[2].y>=p[1].y&&l[2].y<=p[2].y)
		     cout<<"T"<<endl;
		else cout<<"F"<<endl;	
	}
	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