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

我做了这道题,在自己电脑上还没问题,但一提交就Runtime error ,哪位帮忙看一下

Posted by cfdream at 2007-04-15 11:12:41 on Problem 2049
#include<iostream>
using namespace std;
struct grid
{
	int sign;
	int up,down,right,left;
};
void ini_map(grid **map,int rows,int cols)
{
	for(int i=0;i<rows;i++)
		for(int j=0;j<cols;j++)
		{
			map[i][j].down=map[i][j].left=map[i][j].right=map[i][j].up=1;
			map[i][j].sign=0;
		}
}
void ini2_map(grid **map,int i,int j,int d )
{
	if(d==1)
	{
		map[i][j].left=0;
		if((j-1)>0)
			map[i][j-1].right=0;
	}else
	{
		map[i][j].up=0;
		if((i-1)>0)
			map[i-1][j].down=0;
	}
}
int proce(grid **map,int rows,int cols,int ele[1000][2],int ele_no,int nth)
{
	int next_ele_no=0;
	int m=0;
	int next_ele[1000][2];
	for(int i=0;i<ele_no;i++)
	{
		if(ele[i][0]==0||ele[i][0]==rows+1||ele[i][1]==0||ele[i][1]==cols+1)
		{	
			return nth-1;
		}
	}
	for(i=0;i<ele_no;i++)
	{
		int row=ele[i][0];
		int col=ele[i][1];
		if(map[row][col].down==0&&map[row+1][col].sign==0){
			map[row+1][col].sign=nth;
			next_ele[m][0]=row+1;
			next_ele[m][1]=col;
			next_ele_no++;
			m++;
		}
		if(map[row][col].up==0&&map[row-1][col].sign==0){
			map[row-1][col].sign=nth;
			next_ele[m][0]=row-1;
			next_ele[m][1]=col;
			next_ele_no++;
			m++;
		}
		if(map[row][col].right==0&&map[row][col+1].sign==0){
			map[row][col+1].sign=nth;
			next_ele[m][0]=row;
			next_ele[m][1]=col+1;
			next_ele_no++;
			m++;
		}
		if(map[row][col].left==0&&map[row][col-1].sign==0){
			map[row][col-1].sign=nth;
			next_ele[m][0]=row;
			next_ele[m][1]=col-1;
			next_ele_no++;
			m++;
		}
	}
	if(next_ele_no==0)
		return -1;
	return proce(map,rows,cols,next_ele,next_ele_no,nth+1);
}
void main()
{
	int M,N;
	cin>>M>>N;		
	while(M!=-1&&N!=-1)
	{
		int rows,cols;
		rows=cols=(M-2)/2;
		grid **map=new grid*[rows+2];
		for(int i=0;i<rows+2;i++)
		{
			map[i]=new grid[cols+2];
		}
		int i1,j1,d,t;
		for(i=0;i<M;i++)
			cin>>j1>>i1>>d>>t;
		ini_map(map,rows+2,cols+2);
		for(i=0;i<N;i++)
		{
			cin>>j1>>i1>>d;
			ini2_map(map,i1,j1,d);
		}
		float pox,poy;
		cin>>poy>>pox;
		int po1=pox,po2=poy;
		int ele[1000][2];
		int ele_no=1;
		ele[0][0]=po1,ele[0][1]=po2;
		int nth=1;
		cout<<proce(map,rows,cols,ele,ele_no,nth);
		cin>>M>>N;
	}
}

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