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 iowyh at 2006-03-27 16:04:27 on Problem 1088
#include<iostream>

using namespace std;

int way[10000][3],order[10000],how[101][101],gra[101][101];
bool flag[101][101]={false};

int cmp(void const *a,void const *b)
{
	return(way[*(int *)a][0]-way[*(int *)b][0]);
}




int main()
{
	int r,c,i,j,k,temp,max,x,y,xx,yy,hi,hj;
	scanf("%d%d",&r,&c);
	k=0;
	for(i=1;i<=r;i++)
		for(j=1;j<=c;j++)
		{
			scanf("%d",&way[k][0]);
			gra[i][j]=way[k][0];
			way[k][1]=i;
			way[k++][2]=j;
		}

	for(i=0;i<k;i++)
		order[i]=i;

	qsort(order,k,sizeof(int),cmp);
	
			
	
	
	temp=order[0];
	x=way[temp][1];
	y=way[temp][2];
	hi=way[temp][0];
	flag[x][y]=true;
	how[x][y]=1;
	
	
	for(i=1;i<k;i++)
	{
		max=0;
		temp=order[i];
		x=way[temp][1];
		y=way[temp][2];
		hi=way[temp][0];
		
		
				xx=x+1;
				yy=y+0;
				hj=gra[xx][yy];
				if(flag[xx][yy]&&hi!=hj&&how[xx][yy]>max)
					max=how[xx][yy];

				xx=x+0;
				yy=y+1;
				hj=gra[xx][yy];
				if(flag[xx][yy]&&hi!=hj&&how[xx][yy]>max)
					max=how[xx][yy];

				xx=x-1;
				yy=y+0;
				hj=gra[xx][yy];
				if(flag[xx][yy]&&hi!=hj&&how[xx][yy]>max)
					max=how[xx][yy];

				xx=x+0;
				yy=y-1;
				hj=gra[xx][yy];
				if(flag[xx][yy]&&hi!=hj&&how[xx][yy]>max)
					max=how[xx][yy];
	
		
		
		
		
		
		if(max!=0)
			how[x][y]=max+1;
		else how[x][y]=1;

		flag[x][y]=true;
	}
	max=0;

	for(i=1;i<=r;i++)
		for(j=1;j<=c;j++)
		{
			if(how[i][j]>max)
				max=how[i][j];
		}
	printf("%d\n",max);
	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