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

高手请帮忙看看这个为什么是WA

Posted by fatguan at 2006-07-08 08:44:03 on Problem 2766
#include <iostream.h>

static int amount=1;

struct point {
	int x;
	int y;
};

point *getTheNearestPoint(point *originPoint, point *points, int pointSize,int direction) {
	point *temp=new point();

	if(direction==3){
		int small=100;
		for(int i=0;i<pointSize;i++)
			if(points[i].y==originPoint->y && points[i].x<originPoint->x && small>(originPoint->x-points[i].x))
				small=originPoint->x-points[i].x;
		if(small==100){
			temp=NULL;			
		}
		else {
			temp->x=originPoint->x-small;
			temp->y=originPoint->y;
		}
	}

	if(direction==1){
		int small=100;
		for(int i=0;i<pointSize;i++)
			if(points[i].y==originPoint->y && points[i].x>originPoint->x && small>(points[i].x-originPoint->x))
				small=points[i].x-originPoint->x;
		if(small==100){
			temp=NULL;		
		}
		else {
			temp->x=originPoint->x+small;
			temp->y=originPoint->y;
		}
	}
	if(direction==4){
		int small=100;
		for(int i=0;i<pointSize;i++)
			if(points[i].x==originPoint->x && points[i].y>originPoint->y && small>(points[i].y-originPoint->y))
				small=points[i].y-originPoint->y;
		if(small==100){
			temp=NULL;			
		}
		else {
			temp->y=originPoint->y+small;
			temp->x=originPoint->x;
		}
	}

	if(direction==2){
		int small=100;
		for(int i=0;i<pointSize;i++)
			if(points[i].x==originPoint->x && points[i].y<originPoint->y && small>(originPoint->y-points[i].y))
				small=originPoint->y-points[i].y;
		if(small==100){
			temp=NULL;		
		}
		else {
			temp->y=originPoint->y-small;
			temp->x=originPoint->x;
		}
	}

	return temp;
}
				

point *count(int size, point *originPoint, point *points, int pointSize, int direction) {
	point *temp=getTheNearestPoint(originPoint,points,pointSize,direction);
//	if(temp!=NULL)
//		cout<<"nearest :"<<temp->x<<","<<temp->y<<endl;
	if(temp==NULL){
		temp=new point();
		if(direction==3){
			temp->x=0;
			temp->y=originPoint->y;
		}
		if(direction==1){
			temp->x=size;
			temp->y=originPoint->y;
		}
		if(direction==2){
			temp->x=originPoint->x;
			temp->y=0;
		}
		if(direction==4){
			temp->x=originPoint->x;
			temp->y=size;
		}
		return temp;
	}
	else {
		amount++;
		if(amount>200){
			temp->x=0;
			temp->y=0;
			return temp;
		}
		direction++;
		if(direction==5)
			direction=1;
		originPoint->x=temp->x;
		originPoint->y=temp->y;
		return count(size,originPoint,points,pointSize,direction);
	}
}




int main() {
	int testTime;
	cin>>testTime;
	int boardSize,pointSize,direction;
	point *points=NULL;
	point *originPoint=NULL,*finalPoint=NULL;
	for(int i=0;i<testTime;i++) {
		cin>>boardSize;
		cin>>pointSize;
		points=new point[pointSize];
		for(int j=0;j<pointSize;j++)
			cin>>points[j].x>>points[j].y;
		originPoint=new point();
		cin>>originPoint->x>>originPoint->y;
		
		if(originPoint->x>=boardSize && (originPoint->y>=0 && originPoint->y<=boardSize))
			direction=3;
		if(originPoint->x<=0 && (originPoint->y>=0 && originPoint->y<=boardSize))
			direction=1;
		if(originPoint->y>=boardSize && (originPoint->x>=0 && originPoint->x<=boardSize))
			direction=2;
		if(originPoint->y<=0 && (originPoint->x>=0 && originPoint->x<=boardSize))
			direction=4;
    //    cout<<direction;
		finalPoint=count(boardSize,originPoint,points,pointSize,direction);
		cout<<finalPoint->x<<" "<<finalPoint->y<<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