标签:margin rsa out src 结果 lin sub cst print
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 52279 | Accepted: 22018 |
Description
Input
Output
Sample Input
bwwb bbwb bwwb bwww
Sample Output
4
Source
1 #include<iostream> 2 #include<cstdio> 3 #include<cstdlib> 4 #include<cstring> 5 #include<algorithm> 6 #include<cmath> 7 #include<queue> 8 #include<list> 9 #include<vector> 10 #include<stack> 11 #include<string> 12 #include<map> 13 #include<numeric> 14 #include<set> 15 #include<functional> 16 #include<sstream> 17 #include<time.h> 18 using namespace std; 19 int mapp[4][4]; 20 int turn1[5]={1,-1,0,0,0}; 21 int turn2[5]={0,0,0,1,-1}; 22 const int inf = 0x3f3f3f3f; 23 int ans=inf; 24 25 int judge( void ) //判断棋盘是否全为0,或全为1 26 { 27 int temp=mapp[0][0]; 28 for(int i = 0; i<4; i++) 29 { 30 for(int j = 0; j<4; j++) 31 { 32 if(temp != mapp[i][j]) 33 return 0; 34 } 35 } 36 return 1; 37 } 38 39 void turn(int x, int y) 40 { 41 for(int i=0;i<5;i++) 42 { 43 if(x+turn1[i]>=0&&x+turn1[i]<4&&y+turn2[i]>=0&&y+turn2[i]<4) 44 mapp[x+turn1[i]][y+turn2[i]]= !mapp[x+turn1[i]][y+turn2[i]]; 45 } 46 } 47 48 int dfs( int x, int y, int t) 49 { 50 if(judge()) 51 { 52 ans=min(ans,t); 53 return 0; 54 } 55 if(x >= 4 || y >= 4) 56 return 0; 57 int nx=(x+1)%4; //坐标,满4换成第二行 58 int ny=y+(x+1)/4; 59 60 dfs(nx,ny,t); //搜索翻转 61 turn(x,y); 62 dfs(nx,ny,t+1); 63 turn(x,y); 64 65 return 0; 66 } 67 int main() 68 { 69 70 for(int i=0;i<4;i++) 71 { 72 char s[10]; 73 gets(s); 74 for(int j=0;j<4;j++) 75 { 76 if(s[j]==‘b‘) mapp[i][j]=1; 77 else mapp[i][j]=0; 78 } 79 } 80 81 dfs(0,0,0); 82 83 if(ans!=inf) 84 printf("%d\n",ans); 85 else 86 printf("Impossible\n"); 87 }
标签:margin rsa out src 结果 lin sub cst print
原文地址:https://www.cnblogs.com/Tangent-1231/p/9740096.html