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

哪位大牛帮忙看看我写的枚举,已经交了快20遍了

Posted by ydy_kid at 2008-10-10 21:45:34 on Problem 1753
#include<stdio.h>
static int a[65535][2],na,vv[16],c[4][4],flips[16];
int chang(int a[4][4],int vv[16])
{int i,j,k;
 k=0;
 for(i=0;i<4;i++)
  for(j=0;j<4;j++)
   k+=a[i][j]*vv[i*4+j];
  return(k);
}
void tryy(int i,int j,int k);
main()
{int i,j,n,m,aa,bb;
 char s[4];int pp[4][2]={{1,0},{-1,0},{0,1},{0,-1}};
 vv[0]=1;
 for(i=1;i<16;i++)
  vv[i]=vv[i-1]*2;
  for(i=0;i<4;i++)
   for(j=0;j<4;j++)
    c[i][j]=0;
 for(i=0;i<16;i++)
  {aa=i/4;bb=i%4;
    c[aa][bb]=1;      
   for(j=0;j<4;j++)    
     if((aa+pp[j][0]>=0)&&(aa+pp[j][0]<=3)
       &&(bb+pp[j][1]>=0)&&(bb+pp[j][1]<=3))
         c[aa+pp[j][0]][bb+pp[j][1]]=1;   
    flips[i]=chang(c,vv);
    c[aa][bb]=0;
    for(j=0;j<4;j++)
    if((aa+pp[j][0]>=0)&&(aa+pp[j][0]<=3)
    &&(bb+pp[j][1]>=0)&&(bb+pp[j][1]<=3))
     c[aa+pp[j][0]][bb+pp[j][1]]=0; 
       
   }
   m=0; 
   for(i=0;i<4;i++)
    {scanf("%s",s);
     for(j=0;j<4;j++)
       if(s[j]=='p')
         m+=vv[i*4+j];
     } 
   na=-1;
    tryy(m,1,0);
    n=20;
   for(i=0;i<na+1;i++)
    {if((a[i][0]==0)||(a[i][0]==65535))   
      if(a[i][1]<n)n=a[i][1];
     }
  if(n<20)printf("n=%d\n",n);
   else printf("Impossible\n");   
}
void tryy(int i,int j,int k)
{
  if(j>16){na++;a[na][0]=i;a[na][1]=k;return;}
  tryy(i^flips[j],j+1,k+1);
  tryy(i,j+1,k);
}


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