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

这道题只要依次匹配4个节点的完全图就可以了,用邻接矩阵就可以,附代码

Posted by yzhw at 2009-03-10 12:25:50 on Problem 1058
# include <stdio.h>
# include <stdbool.h>
# include <string.h>
char refer[6][25];
bool jud[17][17];
bool used[17];
int chk(int num)
{
    int i,j,k,l,pos=0;
    for(i=1;i<=16;i++)
     for(j=i+1;j<=16;j++)
       for(k=j+1;k<=16;k++)
         for(l=k+1;l<=16;l++)
          if(!used[l]&&!used[i]&&!used[j]&&!used[k])
           if(jud[i][j]&&jud[i][k]&&jud[i][l]&&
              jud[j][i]&&jud[j][k]&&jud[j][l]&&
              jud[k][i]&&jud[k][j]&&jud[k][l]&&
              jud[l][i]&&jud[l][j]&&jud[l][k])
             {
              if(pos>=16) return 0;
              jud[i][j]=jud[i][k]=jud[i][l]=
              jud[j][i]=jud[j][k]=jud[j][l]=
              jud[k][i]=jud[k][j]=jud[k][l]=
              jud[l][i]=jud[l][j]=jud[l][k]=0;
              refer[num][pos++]=i+64;
              refer[num][pos++]=j+64;
              refer[num][pos++]=k+64;
              refer[num][pos++]=l+64;
              used[i]=used[j]=used[k]=used[l]=1;
             }
    if(pos!=16) return 0;
    else return 1;
}
int main()
{
    while(scanf("%s",refer[1])!=EOF)
    {
      char temp[6];
      int i,j,k,l;
      memset(jud,1,sizeof(jud));
      scanf("%s",temp);
      strcat(refer[1],temp);
      scanf("%s",temp);
      strcat(refer[1],temp);
      scanf("%s",temp);
      strcat(refer[1],temp);
      scanf("%s",temp);
      strcpy(refer[2],temp);
      scanf("%s",temp);
      strcat(refer[2],temp);
      scanf("%s",temp);
      strcat(refer[2],temp);
      scanf("%s",temp);
      strcat(refer[2],temp);
      scanf("%s",temp);
      strcpy(refer[3],temp);
      scanf("%s",temp);
      strcat(refer[3],temp);
      scanf("%s",temp);
      strcat(refer[3],temp);
      scanf("%s",temp);
      strcat(refer[3],temp);
      for(i=1;i<=3;i++)
       for(l=0;l<=12;l+=4)
        for(j=l;j<=l+3;j++)
         for(k=l;k<=l+3;k++)
             jud[refer[i][j]-64][refer[i][k]-64]=0;
       memset(used,0,sizeof(used));
       if(chk(4))
       {
        memset(used,0,sizeof(used));
        if(chk(5))
        {
         refer[4][16]=refer[5][16]='\0';
         for(i=1;i<=5;i++)
         {
          for(l=0;l<=12;l+=4)
           {
            for(j=l;j<=l+3;j++) printf("%c",refer[i][j]);
            if(l!=12) printf(" ");
           }
           printf("\n");
          }
          printf("\n");
         }
         else printf("It is not possible to complete this schedule.\n\n");
        }
         else printf("It is not possible to complete this schedule.\n\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