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:加了注释 并修改过的代码,帮忙看看,谢了。(其中对每个位置的操作是用位运算进行的)

Posted by ydy_kid at 2008-10-11 14:30:07 on Problem 1753
In Reply To:哪位大牛帮忙看看我写的枚举,已经交了快20遍了 Posted by:ydy_kid at 2008-10-10 21:45:34
#include<stdio.h>
#include"conio.h" 
static long int na,vv[16]/*存2的次方数*/,c[4][4]/*4*4方格*/,flips[16]/*16个位置操作对应的整形数*/,n;
long int chang(long int a[4][4],long int vv[16])
{long 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);
} /*将4*4二进制转化为整形数*/         
void tryy( long int i,long int j,long int k);/*枚举函数*/
main()
{long int i,j,m,aa,bb;
 char s[4];long int pp[4][2]={{1,0},{-1,0},{0,1},{0,-1}}/*一个位置对应4个位置的坐标操作*/;
 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;
  /*初始化4*4方格*/  
 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; 
   }
   /*记录16个位置位运算操作的整形数*/
   m=0; 
   for(i=0;i<4;i++)
    {scanf("%s",s);
     for(j=0;j<4;j++)
       if(s[j]=='b')
         m+=vv[i*4+j];
     } /*输入*/
   n=20; 
   tryy(m,0,0);/*枚举*/
   if(n<20)printf("%ld\n",n);
   else printf("Impossible\n");/*输出*/   
}
void tryy(long int i,long int j,long int k)
{
  if(j>15)
   {if((i==0)||(i==65535))
     if(k<n)n=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