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

Re:很奇怪,SPFA在ACM/ICPC和zju上过了,这边打死过不料!

Posted by bobchennan at 2009-08-14 15:16:30 on Problem 1275
In Reply To:很奇怪,SPFA在ACM/ICPC和zju上过了,这边打死过不料! Posted by:orlando22 at 2009-04-20 17:53:12
> 我还在期待SPFA超过16MS的表现呢,结果居然是WA!那位兄弟有同样经历,呼吁帮哈忙!
> PS:基本的Bellman-Ford加二分优化是过了滴!谢谢大家捧场哈!
我也是SPFA不知道怎么就是Wrong Answer,怎么搞的啊,哪位大牛帮我看看
#include <stdio.h>
int map[24][24],a[24];
short ok=0,mapb[24][24];
short SPFA(void);
void add(int,int,int);
main()
{
  int i,k,r[24],n,x,j;
  for (scanf("%d*",&k);k--;)
    {
      memset(map,0,sizeof(map));
      memset(mapb,0,sizeof(mapb));
      memset(a,0,sizeof(a));
      for (i=0;i<24;i++)
	scanf("%d*",&r[i]);
      scanf("%d*",&n);
      for (i=0;i<n;i++)
	{
	  scanf("%d*",&x);
	  a[x]++;
	}
      if (n==4)
       {
          printf("No Solution");
          continue;
          }
	  for (i=0;i<24;i++)
	    {
           add(i,i-1,-a[i]);
           add(i-1,i,0);
           if (i>7)
             add(i-8,i,r[i]);
             }
      /*add(0,23,-a[0]);
      add(23,0,0);*/
      for (j=0;j<=n;j++)
	{
	  for (i=0;i<8;i++)
	    add(i+16,i,r[i]-j);
      if (SPFA())
	    {
	      ok=1;
	      break;
	    }
	}
      if (ok) printf("%d\n",j);
      else printf("No Solution\n");
    }
  return 0;
}
short SPFA(void)
{
  int l,x,first,end,z[1000]={0},appear[24]={0},in[24]={0},dist[24]={0};
  z[0]=0,first=0,end=1,in[0]=1;
  for (l=1;l<24;l++)
    dist[l]=-2147483647;
  while (first!=end)
    {
      x=z[first],first++,in[x]=0;
      for (l=0;l<24;l++)
	if (mapb[x][l]&&dist[x]+map[x][l]>dist[l])
	  {
         dist[l]=dist[x]+map[x][l];
         if (!in[l])
	      {
            z[end]=l,end++,in[l]=1;
            appear[l]++;
            if (appear[l]>=30)
              return 0;
            }
	  }
    }
  return 1;
}
void add(s1,s2,s3)
{
     if (s1<0||s2<0||s1>23||s2>23) return;
     map[s1][s2]=s3;
     mapb[s1][s2]=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