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 000 at 2005-08-14 10:25:18 on Problem 1932
#include <stdio.h>

const int MaxN=110;

int graph[MaxN][MaxN];
int n;
int engy[MaxN];

typedef struct
{
	int engery;
	int vetex;
}node;
node qn[100*MaxN];
int front;
int rear;


void init ()
{
	int i,j;
	for (i=0;i<MaxN;i++)
		for (j=0;j<MaxN;j++)
			graph[i][j]=0;
}
 

void getdata ()
{
	scanf ("%d",&n);

	int i,j,k;
	int t;
	for (i=0;i<n;i++)
	{
	   	scanf("%d",&engy[i]);

	    scanf ("%d",&k);
		for (j=0;j<k;j++)
		{
			scanf ("%d",&t);
			graph[i][t-1]=1;
		}
	}
}


void BFS()
{
	front=0;
	rear=0;

	qn[++rear].engery=100;
	qn[rear].vetex =0;

	node e;
	int i;

	for (front=1;front<=rear;front++)
	{
		e=qn[front];

		if (e.vetex ==n-1)  break;

		for (i=0;i<n;i++)
		{
			if (graph[e.vetex][i]==0)  continue;

			if (e.engery+engy[i]<=0)  continue;

			qn[++rear].vetex =i;
			qn[rear].engery =e.engery +engy[i];
		}

	}


	if (front<=rear)
		printf ("winnable\n");
	else
		printf ("hopeless\n");
}




int main ()
{
//	freopen ("in.txt","r",stdin);
	while (true)
	{
		init();

		getdata ();

        if (n==-1)  break;
 
        BFS();		
	}
 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