标签:eof bool play 解决 游戏 ems fda bsp idt
3
00111
01011
10001
11010
11100
11101
11101
11110
11111
11111
01111
11111
11111
11111
11111
3
2
-1
1 #include <bits/stdc++.h> 2 3 inline void read(int &x) 4 { 5 x = 0;char ch = getchar(); 6 char c = ch; 7 while(ch > ‘9‘ || ch < ‘0‘)c = ch, ch = getchar(); 8 while(ch <= ‘9‘ && ch >= ‘0‘)x = x * 10 + ch - ‘0‘, ch = getchar(); 9 if(c == ‘-‘)x = -x; 10 } 11 inline int min(int a, int b){return a > b ? b : a;} 12 13 const int INF = 0x3f3f3f3f; 14 const int MAXN = 50 + 10; 15 16 int g[MAXN][MAXN],n,ans,tmp[MAXN][MAXN]; 17 18 void change(int x, int y) 19 { 20 tmp[x][y] ^= 1; 21 if(x - 1) 22 tmp[x - 1][y] ^= 1; 23 if(y - 1) 24 tmp[x][y - 1] ^= 1; 25 if(y + 1 <= n) 26 tmp[x][y + 1] ^= 1; 27 if(x + 1 <= n) 28 tmp[x + 1][y] ^= 1; 29 } 30 31 int t; 32 char s[MAXN]; 33 34 int main() 35 { 36 read(t); 37 n = 5; 38 for(;t;--t) 39 { 40 memset(g, 0, sizeof(g)); 41 memset(tmp, 0, sizeof(tmp)); 42 ans = INF; 43 for(int i = 1;i <= n;++ i) 44 { 45 scanf("%s", s + 1); 46 for(int j = 1;j <= n;++ j) 47 g[i][j] = (s[j] - ‘0‘) ^ 1; 48 } 49 for(register int s = 0;s < (1 << n);++ s) 50 { 51 for(int i = 1;i <= n;++ i) 52 for(int j = 1;j <= n;++ j) 53 tmp[i][j] = g[i][j]; 54 bool ok = true; 55 register int tmp = s; 56 register int k = 1; 57 int cnt = 0; 58 while(tmp) 59 { 60 if(tmp & 1) 61 change(1, k),++ cnt; 62 ++ k;tmp >>= 1; 63 } 64 for(register int j = 2;j <= n;++ j) 65 for(k = 1;k <= n;++ k) 66 if(::tmp[j - 1][k]) 67 change(j, k), ++ cnt; 68 for(register int j = 1;j <= n;++ j) 69 if(::tmp[n][j]) 70 ok = false; 71 if(ok) 72 ans = min(ans, cnt); 73 } 74 if(ans > 6) 75 printf("-1\n"); 76 else printf("%d\n", ans); 77 } 78 return 0; 79 }
标签:eof bool play 解决 游戏 ems fda bsp idt
原文地址:http://www.cnblogs.com/huibixiaoxing/p/7137752.html