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 20071585 at 2009-11-07 10:51:46 on Problem 1127
#include <iostream>
#include <stdio.h>
using namespace std;

struct POINT
{
	int x;
	int y;
};

struct node
{
	POINT a;
	POINT b;
	int n;
};

int max(int x,int y)
{
	return x>y?x:y;
}

int min(int x,int y)
{
	return x<y?x:y;
}

double solve(POINT sp,POINT ep,POINT op) 
{ 
	return((sp.x-op.x)*(ep.y-op.y)-(ep.x-op.x)*(sp.y-op.y)); 
} 

bool ans(node m,node n) 
{ 
	return( (max(m.a.x,m.b.x)>=min(n.a.x,n.b.x))&&         
		(max(n.a.x,n.b.x)>=min(m.a.x,m.b.x))&& 
		(max(m.a.y,m.b.y)>=min(n.a.y,n.b.y))&& 
		(max(n.a.y,n.b.y)>=min(m.a.y,m.b.y))&& 
		(solve(n.a,m.b,m.a)*solve(m.b,n.b,m.a)>=0)&&       
		(solve(m.a,n.b,n.a)*solve(n.b,m.b,n.a)>=0) ); 
} 


int main()
{
	int num,i,j,k;
	node temp[20];
	bool flag;
	while(scanf("%d",&num)&&num)  
	{
		memset(temp,0,sizeof(temp));
		for(i=0;i<num;i++)
		{
			scanf("%d%d%d%d",&temp[i].a.x,&temp[i].a.y,&temp[i].b.x,&temp[i].b.y);
			temp[i].n=i;
		}
		for(i=0;i<num;i++)
		{
			for(j=0;j<num;j++)
			{
				flag=ans(temp[i],temp[j]) ;
				if(flag)
				{
					temp[j].n=temp[i].n;
				}
			}
		}
		while(scanf("%d%d",&i,&j))
		{
			if(i==0&&j==0)
			{
				break;
			}
			else
			{
				if(temp[i-1].n==temp[j-1].n)
				{
					printf("CONNECTED\n");
				}
				else
				{
					printf("NOT CONNECTED\n");
				}
			}
		}
	}
	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