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 A861223 at 2006-08-21 20:43:43 on Problem 2492
#define maxn 2001
#include<stdio.h>
#include<string.h>
int n,f[maxn][maxn],p[maxn][maxn],use[maxn];
int task()
 {int k,i,j;
  for (k=1;k<=n;k++)
   if (use[k]==1)
	for (i=1;i<=n;i++)
    if (i!=k&&f[i][k]==1)
       for (j=1;j<=n;j++)
         if (i!=j&&j!=k&&f[k][j]==1)
            {f[i][j]=2;f[j][i]=2;
		     if (p[i][j]==1&&p[j][i]==1) return(1);
		 }
   return(0);
}
void main()
{ int x,y,q,m,i1,j1;
  scanf("%d",&q);
  for(i1=1;i1<=q;i1++)
   { scanf("%d %d",&n,&m);
     memset(f,0,sizeof(f));memset(p,0,sizeof(p));
     for (j1=1;j1<=m;j1++)
      {
        scanf("%d %d",&x,&y);
        p[x][y]=1;p[y][x]=1;
        use[x]=1;use[y]=1; 
      }
     memcpy(f,p,sizeof(p));
     printf("Scenario #%d:\n",i1);
     if(task()==1) printf("Suspicious bugs found!\n");
      else printf("No suspicious bugs found!\n");
   }
}

我用了个类似传递闭包的算法

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