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

Who can tell me why the codes iare "wrong answer",the following are the "WA"!codes!!

Posted by kuki at 2010-07-30 02:58:56 on Problem 1928
#include<stdio.h>
#include<memory.h>
#include<math.h>
int a[60][60];
int MAXhuasheng=0;
int M,N,K,Time,number=0;
int n;
//FILE *fp;

int fun(void)
{
	number=0;
	int i,j;
	int currenti,currentj,nexti,nextj;
	memset(a,0,sizeof(a));
	//fscanf(fp,"%d%d%d",&M,&N,&K);
	scanf("%d%d%d",&M,&N,&K);
	Time=K;
	for(i=1;i<=M;i++)
		for(j=1;j<=N;j++)
			//fscanf(fp,"%d",&a[i][j]);
		scanf("%d",&a[i][j]);
		for(i=1;i<=M;i++)
		{
			for(j=1;j<=N;j++)
				if(MAXhuasheng<a[i][j])
				{
					MAXhuasheng=a[i][j];
					nexti=i;
					nextj=j;
				}
		}
		if(MAXhuasheng==0)
			return number;
		else if(nexti*2+1>Time)
			return number;
		else
		{
			number+=MAXhuasheng;
			currenti=nexti;
			currentj=nextj;
			Time-=(nexti+1);
			MAXhuasheng=0;
			a[currenti][currentj]=0;
		}
		while(Time>=0)
		{
			for(i=1;i<=M;i++)
			{
				for(j=1;j<=N;j++)
					if(MAXhuasheng<a[i][j])
					{
						MAXhuasheng=a[i][j];
						nexti=i;
						nextj=j;
					}
			}
			if(MAXhuasheng==0)
				return number;
			else if((abs(currenti-nexti)+abs(currentj-nextj)+1+nexti)>Time)
				return number;
			else
			{
				Time-=(abs(currenti-nexti)+abs(currentj-nextj)+1);
				currenti=nexti;
				currentj=nextj;
				number+=MAXhuasheng;
				MAXhuasheng=0;
				a[currenti][currentj]=0;
			}	
		}
		
		return number;
}

int main()
{
	//fp=fopen("G:\\C++文件\\std.txt","r");
	//fscanf(fp,"%d",&n);
	scanf("%d",&n);
	for(int k=0;k<n;k++)
	{
		printf("%d\n",fun());
	}
	//fclose(fp);
	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