A:Broadcast Stations
留坑。
B:Connect3
题意:四个栈,每次放棋子只能放某个栈的栈顶,栈满不能放,现在给出(1, x) 表示黑子放在第x个栈的第一个位置,白子放在第b个栈的第a个位置并且是胜利局势的情况有几种,只要有三个相同的连在一起就是赢了
思路:数据很小,暴力搜索即可,注意判重。
1 #include <bits/stdc++.h> 2 3 using namespace std; 4 5 int x, a, b; 6 7 int G[10][10]; 8 9 // 0 not done 10 // 1 white 11 // 2 black 12 13 inline string Hash() 14 { 15 string ans = ""; 16 for (int i = 1; i <= 4; ++i) 17 for (int j = 1; j <= 4; ++j) 18 { 19 ans += G[i][j] + '0'; 20 } 21 return ans; 22 } 23 24 map <string, bool> mp; 25 26 int cnt[10]; 27 28 inline bool ok(int x, int y) 29 { 30 if (x < 0 || x > 4 || y < 0 || y > 4) return false; 31 return true; 32 } 33 34 int Move[][2] = 35 { 36 0, 1, 37 0, -1, 38 1, 0, 39 -1, 0, 40 -1, -1, 41 -1, 1, 42 1, -1, 43 1, 1, 44 }; 45 46 inline bool check(int x, int y) 47 { 48 int color = G[x][y]; 49 for (int i = 0; i < 8; ++i) 50 { 51 int nx = x + Move[i][0]; 52 int ny = y + Move[i][1]; 53 int nnx = nx + Move[i][0]; 54 int nny = ny + Move[i][1]; 55 if (ok(nx, ny) && ok(nnx, nny)) 56 if (G[nx][ny] == color && G[nnx][nny] == color) 57 return true; 58 nx = x + Move[i][0]; 59 ny = y + Move[i][1]; 60 nnx = x - Move[i][0]; 61 nny = y - Move[i][1]; 62 if (ok(nx, ny) && ok(nnx, nny)) 63 if (G[nx][ny] == color && G[nnx][nny] == color) 64 return true; 65 } 66 return false; 67 } 68 69 int tot; 70 71 inline void DFS(int x, int y, int vis) 72 { 73 if (check(x, y)) 74 { 75 if (vis == 1) return; 76 if (x == b && y == a) 77 { 78 string s = Hash(); 79 if(mp[s] == false) 80 { 81 mp[s] = true; 82 tot++; 83 } 84 } 85 return; 86 } 87 // if (x == b && y == a) 88 // { 89 // if (check()) 90 // { 91 // string s = Hash(); 92 // if (mp[s] == false) 93 // { 94 // mp[s] = true; 95 // tot++; 96 // } 97 // } 98 // return; 99 // } 100 for (int i = 1; i <= 4; ++i) 101 { 102 if (cnt[i] < 4) 103 { 104 cnt[i]++; 105 G[i][cnt[i]] = vis; 106 DFS(i, cnt[i], vis == 1 ? 2 : 1); 107 G[i][cnt[i]] = 0; 108 cnt[i]--; 109 } 110 } 111 } 112 113 inline void Init() 114 { 115 memset(cnt, 0, sizeof cnt); 116 memset(G, 0, sizeof G); 117 mp.clear(); 118 tot = 0; 119 } 120 121 122 int main() 123 { 124 while (scanf("%d%d%d", &x, &a, &b) != EOF) 125 { 126 Init(); 127 cnt[x]++; G[x][1] = 2; 128 DFS(x, 1, 1); 129 cout << tot << endl; 130 } 131 }