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 |
枚举怎么才能不TLE呢?#include<stdio.h> int a[6][6]; int b[6][6]; int re[20][2]; int an; void turn(int i,int j) { int ii; b[i][j]=1-b[i][j]; for(ii=1;ii<=4;ii++) { if(j!=ii) b[i][ii]=1-b[i][ii]; if(i!=ii) b[ii][j]=1-b[ii][j]; } } void main() { int i,j,flag,k,t; int min=1000000; char ch; int ge,x,y; for(i=1;i<=4;i++) { for(j=1;j<=4;j++) { ch=getchar(); if(ch=='-') a[i][j]=1; else a[i][j]=0; } ch=getchar(); } for(i=0;i<(1<<16);i++) { flag=0; for(j=1;j<=4;j++) for(k=1;k<=4;k++) { b[j][k]=a[j][k]; } for(j=0;j<16;j++) { if((i&(1<<j))!=0) { x=j/4+1; y=j%4+1; flag++; turn(x,y); } } ge=b[1][1]; t=0; if(ge==0) t=1; else for(j=1;j<=4;j++) for(k=1;k<=4;k++) { if(ge!=b[j][k]) { t=1; break; } } if(t==0) { if(min>flag) { min=flag; an=i; } } } printf("%d\n",min); for(i=0;i<16;i++) { if((an&(1<<i))!=0) printf("%d %d\n",i/4+1,i%4+1); } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator