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 jinright at 2010-05-07 16:00:02 on Problem 1088
#include <stdio.h>
#include <malloc.h>
#include <string.h>

int *h;
int *h2;
int *f;
int R,C;

#define max(a,b) (((a) > (b)) ? (a) : (b))

bool IsHaveSmaller(int i)
{
	int nNum = (*(h+i))-1;

	if (nNum <0)
		return false;
	//判断是否靠左
	if (i % C != 0)
		if ((nNum == *(h+i-1)) &&
			*(f+i-1))
			return true;
	//判断是否靠右
	if (i % C != C-1)
		if ((nNum == *(h+i+1)) &&
			*(f+i+1) > 1)
			return true;
	//判断是否靠上
	if (i >= C)
		if ((nNum == *(h+i-C)) &&
			*(f+i-C))
			return true;
	//判断是否靠下
	if (i < C*R-C)
		if ((nNum == *(h+i+C)) &&
			*(f+i+C) > 1)
			return true;
	return false;
}

int main()
{
    scanf("%d %d",&R, &C);
	int num	= R * C;
	int size	= num * sizeof(int);
	h	= (int*)malloc(size);
    h2 = (int*)malloc(size);
	int *t	= (int*)malloc(size);
	f	= (int*)malloc(size);
	int *ph = h;
	int i;
	for(i=0;i < num;i++)
	{
		scanf("%d",ph+i);
		*(f+i) = 2;
	}
	memcpy(t,h,size);
	memcpy(h2,h,size);
	bool isGet = false;
	while(true)
	{
		isGet = false;
		for (i= 0;i < num;i++)
		{
			if(*(f+i) != 2)
			{
				if (*(f+i) == 1)
					*(f+i) = 0;
				continue;
			}
			if(IsHaveSmaller(i))
			{
				*(h2+i) = *(h+i) -1;
				isGet	= true;
			}
			else
			{
				*(h2+i) = *(h+i);
				*(f+i)	= 1;
			}
		}
		ph	= h;
		h	= h2;
		h2	= ph;
		if (!isGet)
			break;
	}
	int nRes = 0;
	for (i= 0;i < num;i++)
	{
		int num1 = *(t+i);
		int num2 = *(h2+i);
		nRes = max((*(t+i)-*(h2+i)),nRes);
	}
	printf("%d",nRes+1);
    return 1;
}

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