Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Re:帮忙看看,为什么re?实在不明白了In Reply To:帮忙看看,为什么re?实在不明白了 Posted by:Maybesky at 2007-12-13 14:19:47 > #include <iostream> > using namespace std; > > bool occupancy(int i, int j, int d) > { > if(d==1) > return true; > int x,y; > x = i; > y = j; > if (d==2) > { > if ( (x==0 && y ==1) || (x==1 && y ==0) || (x==1 && y ==2) || (x==2 && y==1) ) > return false; > else > return true; > } > int len = 1; > for(x=2; x<d; x++) > len *= 3; > if(i < len) > x = 0; > else if(i < 2*len) > x = 1; > else > x = 2; > if(j < len) > y = 0; > else if(j < 2*len) > y = 1; > else > y = 2; > if ( (x==0 && y ==1) || (x==1 && y ==0) || (x==1 && y ==2) || (x==2 && y==1) ) > return false; > return occupancy(i-x*len, j-y*len, d-1); > } > > int main() > { > int d, i, j; > while(true) > { > scanf("%d", &d); > if(d==0) break; > int wid = 1; > for(i=1; i<d; i++) > wid *= 3; > for(i=0; i<wid; i++) > { > for(j=0; j<wid; j++) > { > if( occupancy(i ,j , d)) > printf("X"); > else > printf(" "); > } > printf("\n"); > } > printf("-\n"); > } > return 0; > } if(d==0) break;该为if(d==-1) break; 就OK了 Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator