| ||||||||||
Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
贴代码了,帮忙看看吧,谢谢了#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator