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:谁的代码比我长?In Reply To:谁的代码比我长? Posted by:liuweibiao at 2012-02-19 14:35:48 > #include<iostream> > using namespace std; > char s[4][4]; > int a[4][4]; > int b[4][4]; > void flip(int i,int j) > { > if(i<3) > b[i+1][j]^=1; > if(i>0) > b[i-1][j]^=1; > if(j<3) > b[i][j+1]^=1; > if(j>0) > b[i][j-1]^=1; > b[i][j]^=1; > } > int main() > { > int i,j,k,l,m,n; > for(i=0;i<4;i++) > { > for(j=0;j<4;j++) > { > scanf("%c",&s[i][j]); > if(s[i][j]=='\n') > j--; > if(s[i][j]=='b') > a[i][j]=1; > } > } > int count=0,max=17; > memcpy(b,a,sizeof(a)); > /*for(i=0;i<4;i++) > { > for(j=0;j<4;j++) > printf("%d",a[i][j]); > printf("\n"); > for(j=0;j<4;j++) > printf("%d",b[i][j]); > printf("\n"); > }*/ > int indix=1; > for(i=1;i<4;i++) > { > for(j=0;j<4;j++) > if(b[i-1][j]==indix) > { > flip(i,j); > count++; > } > } > if(b[3][0]+b[3][1]+b[3][2]+b[3][3]==0) > max=count; > memcpy(b,a,sizeof(a)); > for(k=0;k<4;k++) > { > count=1; > flip(0,k); > for(i=1;i<4;i++) > { > for(j=0;j<4;j++) > if(b[i-1][j]==indix) > { > flip(i,j); > count++; > } > } > if(b[3][0]+b[3][1]+b[3][2]+b[3][3]==0) > if(max>count) > max=count; > memcpy(b,a,sizeof(a)); > } > for(k=0;k<3;k++) > { > for(l=k+1;l<4;l++) > { > count=2; > flip(0,k); > flip(0,l); > for(i=1;i<4;i++) > { > for(j=0;j<4;j++) > if(b[i-1][j]==indix) > { > flip(i,j); > count++; > } > } > if(b[3][0]+b[3][1]+b[3][2]+b[3][3]==0) > if(max>count) > max=count; > memcpy(b,a,sizeof(a)); > } > } > for(k=0;k<4;k++) > { > count=3; > for(l=0;l<4;l++) > if(l!=k) > flip(0,l); > for(i=1;i<4;i++) > { > for(j=0;j<4;j++) > if(b[i-1][j]==indix) > { > flip(i,j); > count++; > } > } > if(b[3][0]+b[3][1]+b[3][2]+b[3][3]==0) > if(max>count) > max=count; > memcpy(b,a,sizeof(a)); > } > count=4; > for(k=0;k<4;k++) > flip(0,k); > for(i=1;i<4;i++) > { > for(j=0;j<4;j++) > if(b[i-1][j]==indix) > { > flip(i,j); > count++; > } > } > if(b[3][0]+b[3][1]+b[3][2]+b[3][3]==0) > if(max>count) > max=count; > memcpy(b,a,sizeof(a)); > indix=0; > count=0; > //if(max==17) > //{ > for(i=1;i<4;i++) > { > for(j=0;j<4;j++) > if(b[i-1][j]==indix) > { > flip(i,j); > count++; > } > } > if(b[3][0]+b[3][1]+b[3][2]+b[3][3]==4) > if(max>count) > max=count; > memcpy(b,a,sizeof(a)); > for(k=0;k<4;k++) > { > count=1; > flip(0,k); > for(i=1;i<4;i++) > { > for(j=0;j<4;j++) > if(b[i-1][j]==indix) > { > flip(i,j); > count++; > } > } > if(b[3][0]+b[3][1]+b[3][2]+b[3][3]==4) > if(max>count) > max=count; > memcpy(b,a,sizeof(a)); > } > for(k=0;k<3;k++) > { > for(l=k+1;l<4;l++) > { > count=2; > flip(0,k); > flip(0,l); > for(i=1;i<4;i++) > { > for(j=0;j<4;j++) > if(b[i-1][j]==indix) > { > flip(i,j); > count++; > } > } > if(b[3][0]+b[3][1]+b[3][2]+b[3][3]==4) > if(max>count) > max=count; > memcpy(b,a,sizeof(a)); > } > } > for(k=0;k<4;k++) > { > count=3; > for(l=0;l<4;l++) > if(l!=k) > flip(0,l); > for(i=1;i<4;i++) > { > for(j=0;j<4;j++) > if(b[i-1][j]==indix) > { > flip(i,j); > count++; > } > } > if(b[3][0]+b[3][1]+b[3][2]+b[3][3]==4) > if(max>count) > max=count; > memcpy(b,a,sizeof(a)); > } > count=4; > for(k=0;k<4;k++) > flip(0,k); > for(i=1;i<4;i++) > { > for(j=0;j<4;j++) > if(b[i-1][j]==indix) > { > flip(i,j); > count++; > } > } > if(b[3][0]+b[3][1]+b[3][2]+b[3][3]==4) > if(max>count) > max=count; > //} > if(max==17) > printf("Impossible\n"); > else > printf("%d\n",max); > return 0; > } > Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator