chessboard_and_queens.cpp (901B)
1 #include <bits/stdc++.h> 2 3 using namespace std; 4 5 using ui = unsigned int; 6 using l = long; 7 using ul = unsigned long; 8 using ll = long long; 9 using ull = unsigned long long; 10 11 using vi = vector<int>; 12 using vui = vector<ui>; 13 using vl = vector<l>; 14 using vul = vector<ul>; 15 using vll = vector<ll>; 16 using vull = vector<ull>; 17 18 int column[8]; 19 int diag1[15]; 20 int diag2[15]; 21 int c[8][8]; 22 int res = 0; 23 24 void search(int y) { 25 if (y == 8) { 26 res++; 27 return; 28 } 29 for (int x = 0; x < 8; x++) { 30 if (column[x] || diag1[x + y] || diag2[x - y + 7]) 31 continue; 32 if (c[x][y]) 33 continue; 34 column[x] = diag1[x + y] = diag2[x - y + 7] = 1; 35 search(y + 1); 36 column[x] = diag1[x + y] = diag2[x - y + 7] = 0; 37 } 38 } 39 40 void solve() 41 { 42 string l; 43 for (int i = 0; i < 8; i++) { 44 getline(cin, l); 45 for (int j = 0; j < 8; j++) { 46 c[i][j] = (l[j] == '*'); 47 } 48 } 49 50 search(0); 51 cout << res << "\n"; 52 } 53 54 int main() 55 { 56 solve(); 57 }