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 allencxz at 2007-10-02 21:49:35 on Problem 3408
#include "stdio.h"
#include "stdlib.h"
struct item{
int D;
struct item *next;
};
struct item *head[1001];
int n,x[1001],bestL,cL,NO;
int Judge(int i)
 { int flag,flag1;
   struct item *p;
   flag1=flag=0;
   p=head[i];
   while(p!=NULL)
    {if(!x[p->D]) {x[p->D]=1;flag=1;}
     p=p->next;
    }
   if(flag==1)
   {p=head[i];
    while(p!=NULL)
    {if(Judge(p->D)) flag1=1;
	  p=p->next;
    }
   }
   if(flag1) cL++;
   if(flag) return 1;
   else return 0;
 }
int insert(int i,int j)
 {struct item *p;
  p=(struct item *)malloc(sizeof(struct item));
  p->D=j;
  p->next=head[i];
  head[i]=p;
  return 0; 
 }
int main()
 {int i,j,k;
  while(scanf("%d",&n)!=EOF)
   {for(i=0;i<1001;i++)
    head[i]=NULL;
    for(i=1;i<=n;i++)
     {scanf("%d",&j);
      while(j--)
        {scanf("%d",&k);
         insert(i,k);
        }
     }
    NO=-1;bestL=-1;
    for(i=1;i<=n;i++)
     {for(j=1;j<=n;j++) x[j]=0;
      cL=0;
	  x[i]=1;
      if(Judge(i)) cL++;
	  for(j=1;j<=n;j++)
		if(x[j]==0) break;
      if((cL>bestL||cL==bestL&&i>NO)&&j>n) {bestL=cL;NO=i;}
     }
    if(bestL!=-1) printf("%d\n%d\n",bestL,NO);
    else printf("impossible\n");
   }
  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