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 xcszbdnl at 2012-07-16 20:34:06 on Problem 1088
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct node
{
	int x;
	int y;
	int value;
}a[10100];
int cmp(const void *a,const void *b){
	struct node *p1,*p2;
	p1=(struct node *)a;
	p2=(struct node *)b;
	if(p1->value>p2->value)
		return 1;
	else
		return -1;
}
int value[110][110];
int f[110][110];
int main()
{
	int r,c,i,j,k;
	int cx,cy,maxh;
	scanf("%d%d",&r,&c);
	memset(f,sizeof(f),0);
	memset(value,sizeof(value),0);
	k=0;
	maxh=0;
	for(i=1;i<=r;i++){
		for(j=1;j<=c;j++){
			scanf("%d",&value[i][j]);
			a[k].value=value[i][j];
			a[k].x=i;
			a[k].y=j;
			k++;
		}
	}
	qsort(a,k,sizeof(struct node),cmp);
	for(i=0;i<k;i++){
		cx=a[i].x;
		cy=a[i].y;
		if(cx>1){
			if(a[i].value<value[cx-1][cy]&&f[cx][cy]>=f[cx-1][cy])
				f[cx-1][cy]=f[cx][cy]+1;
		}
		if(cx<c){
			if(a[i].value<value[cx+1][cy]&&f[cx][cy]>=f[cx+1][cy])
				f[cx+1][cy]=f[cx][cy]+1;
		}
		if(cy>1){
			if(a[i].value<value[cx][cy-1]&&f[cx][cy]>=f[cx][cy-1])
				f[cx][cy-1]=f[cx][cy]+1;
		}
		if(cy<r){
			if(a[i].value<value[cx][cy+1]&&f[cx][cy]>=f[cx][cy+1])
				f[cx][cy+1]=f[cx][cy]+1;
		}
	}
	for(i=1;i<=r;i++){
		for(j=1;j<=c;j++){
			if(f[i][j]>maxh)
				maxh=f[i][j];
		}
	}
	if(maxh!=0)
		maxh++;
	printf("%d\n",maxh);
	//system("pause");
	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