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

1088我的答案怎么不对呢

Posted by yuriarthas at 2011-12-14 22:42:12 on Problem 1088
//总是wrong error,我自己测试的没错阿,是什么地方逻辑错误还是什么地方不符合规范呢?
#include<iostream>

using namespace std ;


int Fun(int *map,int *map2,int m,int n) ;
int Refun(int *map,int *map2,int m,int n,int i,int j) ;

int main()
{
	int m,n ;
	cin>>m>>n ;

	if(m<1)
		return 0 ;
	if(n>100)
		return 0 ;
	int *map,*map2 ;
	map=new int[m*n] ;
	map2=new int [m*n] ;

	int i ;
	for(i=0;i<m*n;i++)
	{
		cin>>map[i] ;
		if(map[i]<0 || map[i]>10000)
			return 0 ;

	}
	for(i=0;i<m*n;i++)
	{
		map2[i]=-1 ;
	}

	int result=Fun(map,map2,m,n) ;

	delete [] map ;
	delete [] map2 ;

	cout<<endl ;
	cout<<result<<endl ;
	return 0 ;
}

int Fun(int *map,int *map2,int m,int n)
{
	bool flag=1 ;
	int i ;
	int j,k ;
	while(flag)
	{
		flag=0 ;
		for(i=0;i<m*n;i++)
		{
			if(map2[i]==-1)
			{
				j=i/n ;
				k=i%n ;
				map2[i]=Refun(map,map2,m,n,j,k) ;
				flag=1 ;
			}
		}
	}
	int max=-9999 ;
	for(i=0;i<m*n;i++)
	{
		if(map2[i]>max)
		{
			max=map2[i] ;
		}
	}
	return max ;
}

int Refun(int *map,int *map2,int m,int n,int i,int j)
{
	int t=map[i*n+j] ;
	int p,q ;
	int mapNum[4]={-1,-1,-1,-1} ;
	if((p=i-1)>=0)
	{
		q=j ;
		if(map[p*n+q]<t)
		{
			if(map2[p*n+q]>0)
				mapNum[0]=map2[p*n+q] ;
			else map2[p*n+q]=mapNum[0]=Refun(map,map2,m,n,p,q) ;
		}
	}
	if((p=i+1)<m)
	{
		q=j ;

		if(map[p*n+q]<t)
		{
			if(map2[p*n+p]>0)
				mapNum[1]=map2[p*n+p] ;
			else map2[p*n+q]=mapNum[1]=Refun(map,map2,m,n,p,q) ;
		}
	}
	if((q=j-1)>=0)
	{
		p=i ;
		if(map[p*n+q]<t)
		{
			if(map2[p*n+q]>0)
				mapNum[2]=map2[p*n+q] ;
			else map2[p*n+q]=mapNum[2]=Refun(map,map2,m,n,p,q) ;
		}
	}
	if((q=j+1)<n)
	{
		p=i ;
		if(map[p*n+q]<t)
		{
			if(map2[p*n+q]>0)
				mapNum[3]=map2[p*n+p] ;
			else map2[p*n+q]=mapNum[3]=Refun(map,map2,m,n,p,q) ;
		}
	}

	int max=-999 ;
	for(int temp=0;temp<4;temp++)
	{
		if(mapNum[temp]>max)
			max=mapNum[temp] ;
	}
	if(max<0)
		map2[i*n+j]=1 ;
	else map2[i*n+j]=max+1 ;

	return map2[i*n+j] ;
}


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