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

Re:我日,又贴代码,还不如不说的好.

Posted by GetAC at 2008-08-26 18:52:41 on Problem 1410
In Reply To:我有话要说! Posted by:ecjtuQX at 2008-08-26 17:50:55
> #include<stdio.h>
> #include<math.h>
> #define EPS 1e-9
> //定义点
> typedef struct Point
> {
> 	double x;
> 	double y;
> }Point;
> //定义线段
> typedef struct Lineseg
> {
> 	Point st;
> 	Point ed;
> }Lineseg;
> //两个向量的叉积
> double mult(Point a,Point b,Point c)
> {
> 	return (a.x-c.x)*(b.y-c.y)-(b.x-c.x)*(a.y-c.y);
> }
> //求最大值
> double MAX(double x,double y)
> {
> 	if(x>y)
> 		return x;
> 	return y;
> }
> //求最小值
> double MIN(double x,double y)
> {
> 	if(x>y)
> 		return y;
> 	return x;
> }
> //判断两线段是不是相交--这也是这个题目最主要的函数
> bool intersect(Lineseg u,Lineseg v)
> {//排斥实验
> 	//+
>  //跨立实验
> 	return MAX(u.st.x,u.ed.x)>=MIN(v.st.x,v.ed.x)
> 		&& MAX(v.st.x,v.ed.x)>=MIN(u.st.x,u.ed.x)
> 		&& MAX(u.st.y,u.ed.y)>=MIN(v.st.y,v.ed.y)
> 		&& MAX(v.st.y,v.ed.y)>=MIN(u.st.y,u.ed.y)
> 		&& mult(v.st,u.ed,u.st)*mult(u.ed,v.ed,u.st)>=0
> 		&& mult(u.st,v.ed,v.st)*mult(v.ed,u.ed,v.st)>=0;
> }
> //判断线段是不是同四边形的边相交 如果相交则返回true 否则返回 false
> bool judge(Point p1,Point p2,Point p3,Point p4,Lineseg l1)
> {
> 	Lineseg l2;
> 	l2.st=p1;
> 	l2.ed=p2;
> 	if(intersect(l1,l2))
> 		return true;
> 	l2.st=p2;
> 	l2.ed=p3;
> 	if(intersect(l1,l2))
> 		return true;
> 	l2.st=p3;
> 	l2.ed=p4;
> 	if(intersect(l1,l2))
> 		return true;
> 	l2.st=p4;
> 	l2.ed=p1;
> 	if(intersect(l1,l2))
> 		return true;
> 	return false;
> }
> 
> int main()
> {
> 	int T;
> 	Lineseg l;
> 	Point p1,p2,p3,p4;
> 	double temp;
> 	scanf("%d",&T);
> 	while(T--)
> 	{
> 		scanf("%lf%lf%lf%lf",&l.st.x,&l.st.y,&l.ed.x,&l.ed.y);
> 		scanf("%lf%lf%lf%lf",&p1.x,&p1.y,&p3.x,&p3.y);
> 		/*
> 		很重要的地方 应为它给的坐标 不一定是 x1<x3 y1>y3 我自己要转化
> 		*/
> 		if(p1.x>p3.x)
> 		{
> 			temp=p1.x;
> 			p1.x=p3.x;
> 			p3.x=temp;
> 		}
> 		if(p1.y<p3.y)
> 		{
> 			temp=p1.y;
> 			p1.y=p3.y;
> 			p3.y=temp;
> 		}
> 		//最重要的地方 判断线段的端点是不是在四边形中 如果在肯定相交 
> 		//这样做的目的是防止线段不同四边形的边相交 但是线段的整体切在四边形中 明白了吗?
> 		// 线段在四边形中也是T 很多人是在这个地方卡到了啊 这个题目很变态的啊! 
> 		if((p1.x<=l.st.x&&l.st.x<=p3.x&&p3.y<=l.st.y&&l.st.y<=p1.y)||
>            (p1.x<=l.ed.x&&l.ed.x<=p3.x&&p3.y<=l.ed.y&&l.ed.y<=p1.y))
> 		{
> 			printf("T\n");
> 			continue;
> 		}
> 		//将矩形的四个顶点分别求出来啊!
> 		//其他的不说了 很简单的啊!
> 		p2.x=p1.x;
> 		p2.y=p3.y;
> 		p4.x=p3.x;
> 		p4.y=p1.y;
> 		if(judge(p1,p2,p3,p4,l))
> 			printf("T\n");
> 		else
> 			printf("F\n");
> 	}
> 	return 0;
> }
> 
> /*
> 1
> 4 9 11 2 1 5 7 1
> F
> 
> */	

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