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 season2243 at 2007-05-13 20:41:21 on Problem 1062
#include <stdio.h>

typedef struct
{
	int rare;
	int level;
	int nextPoint[100][2];
}Point;

Point point[100];
int level[2];//交易的人中等级最高的和最低的
int m,num;

int input()
{
	int i,j;

	scanf ("%d%d",&m,&num);
	for (i=0;i<num;++i)
	{
		scanf("%d%d%d",&point[i].rare,&point[i].level,&point[i].nextPoint[0][0]);
		for (j=1;j<=point[i].nextPoint[0][0];++j)
			scanf("%d%d",&point[i].nextPoint[j][0],&point[i].nextPoint[j][1]);
	}
	level[0]=level[1]=point[0].level;

	return 0;
}

int output(int n)
{
	int i,temp,min=point[n].rare;

	if (point[n].nextPoint[0][0]==0)
		return point[n].rare;

	for (i=1;i<=point[n].nextPoint[0][0];++i)
	{
		temp=output(point[n].nextPoint[i][0]-1);
		temp+=point[n].nextPoint[i][1];
		if ((temp<min) && ((point[n].level+m)>=level[1]) && ((point[n].level-m)<=level[0]))
			min=temp;
		if (point[n].level>level[1])
			level[1]=point[n].level;
		if (point[n].level<level[0])
			level[0]=point[n].level;
	}

	return min;
}

int main ()
{
	input();
	printf ("%d",output(0));

	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