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

AC了的程序,仅供参考

Posted by A861223 at 2006-08-23 22:17:15 on Problem 2446
#define maxn 33
#include<string.h>
#include<stdio.h>
int cover[maxn*maxn],link[maxn*maxn];
int n,m,k,num,f[maxn*maxn][maxn*maxn],d[maxn][maxn],use[maxn][maxn];
void task1()
 {int t,i,j,x,y;
  scanf("%d %d %d",&n,&m,&k);
  memset(f,0,sizeof(f));memset(d,0,sizeof(d));memset(use,0,sizeof(use));
  for (i=1;i<=k;i++)
   {
     scanf("%d %d",&y,&x);
     use[x][y]=1;
   }
  num=0;
  for (i=1;i<=n;i++)
   for (j=1;j<=m;j++)
    if (use[i][j]==0) {num+=1;d[i][j]=num;};
  for (i=1;i<=n;i++)
   for (j=1;j<=m;j++)
    if (use[i][j]==0)
       { t=d[i][j];
         if (i-1>=1&&use[i-1][j]==0) f[t][d[i-1][j]]=1;
         if (j-1>=1&&use[i][j-1]==0) f[t][d[i][j-1]]=1;
         if (i+1<=n&&use[i+1][j]==0) f[t][d[i+1][j]]=1;
         if (j+1<=m&&use[i][j+1]==0) f[t][d[i][j+1]]=1;
       } 
}
int find(int i)
 { int b,q,z;
   z=0;
  for(b=1;b<=num;b++)
   if (f[i][b]==1&&cover[b]==0)
       {
         q=link[b];link[b]=i;cover[b]=1;
         if (q==0||find(q)==0) return(z);
         link[b]=q;
       }
   z=1;
   return(z);
}
void maintask()
{int i;
 for (i=1;i<=num;i++)
  {
   memset(cover,0,sizeof(cover));
   find(i);
  }
}
void task2()
 {int i,z;
  z=0;
  
  for (i=1;i<=num;i++) 
	if (link[i]==0) 
	{z=1;break;}
  
  if (z==1) printf("NO\n");
     else printf("YES\n");
}
void main()
{ 
  task1();
  num=n*m-k;
  maintask();
  task2();  
} 

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