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 nihongjin at 2014-04-08 16:45:36 on Problem 1915 and last updated at 2014-04-08 16:55:46
#include<iostream>
#include<queue>
using namespace std;
int step;
int rear, top, L;

class Point{
protected:
	int x;
    int y;
	
public:
	int step;
	Point(int i = -1, int j = -1)
	{
		this->x = i;
		this->y = j;
		this ->step = 0;
	}
	void reset(){
	  x = -1;
	  y = -1;
	  step = 0;
	}
	int getx(){return this->x;}
	int gety(){return this->y;}
	int gets(){return this ->step;}
	bool operator==(Point pointy)
	{
		if(this->x == pointy.x && this->y == pointy.y)
			return true;
		else
			return false;
	}
	void setS(int i){this ->step = i;}
};

Point point[8];
Point Aqueue[999999];  //数组开的小一点就RE,大一点就WA
bool vis[305][305];
//int step[200];
void move(Point start, int L){
	int x = start.getx();
	int y = start.gety();
	if( x + 1 < L )
	{
		if(y - 2 >= 0)
		 point[0]= Point(x+1,y-2);
		if(y+2 < L)
	     point[1] = Point(x+1, y+2);
	}
	if( x - 1 >= 0 )
	{
		if(y - 2 >= 0)
		 point[2]= Point(x-1,y-2);
		if(y+2 < L)
	     point[3] = Point(x-1, y+2);
	}
	if(x +2 < L)
	{
	  	if(y - 1 >= 0)
		 point[4]= Point(x+2,y-1);
		if(y+1 < L)
	     point[5] = Point(x+2, y+1);
	}
	if(x -2 >= 0)
	{
	  if(y-1 >= 0)
		   point[6] = Point(x-2, y-1);
	  if(y+1 < L)
	       point[7] = Point(x-2, y+1);
	}
}

bool bfs(Point pointx, Point pointy){
	int i;
	while(rear > top){
	   Point state = Aqueue[top ++];
	   if(state == pointy)
	   {
		   cout << state.gets()<<endl;
		   return true;
	   }
	    move(state, L);
	   for(i = 0; i < 8; i++)
	   {
	      if( point[i].getx() != -1 && point[i].gety() !=-1 && !vis[point[i].getx()][point[i].gety()] )
		  {
			//state.step = point[i].gets() + 1;
			point[i].setS( state.gets()+1 );
			 Aqueue[rear++] = point[i];
			vis[point[i].getx()][point[i].gety()] = true;
		  }
	   }
	}
	return false;
}

int main(){
	int N, x, y, i;
	rear = 0;
	top = 0;
	cin >> N;
	while(N--){
		memset(vis, false, sizeof(vis));
		memset(Aqueue, 0, sizeof(Aqueue));
		cin >> L;
		cin >> x >> y;
	    vis[x][y] = true;
		Point pointx = Point(x, y);
	   cin >> x >> y;
	   Point pointy = Point(x, y);
	   for(i = 0; i < 8; i++)
		    point[i].reset();
	   Aqueue[rear++] = pointx;
	   bfs(pointx, pointy);
	  
	}
	return 1;
	//system("pause");
}

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