-
-
Save Bostonncity/4075c15405833e480ed8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <cstdio> | |
#include <cstdlib> | |
#include <vector> | |
#include <map> | |
#include <string> | |
#include <cstring> | |
//#include <unordered_map> | |
#include <queue> | |
#include <algorithm> | |
using namespace std; | |
#define INF (1<<30) | |
#define F first | |
#define S second | |
#define mkp(a, b) make_pair(a, b) | |
const int dx[] = {-1, 0, 1, 0}; | |
const int dy[] = {0, 1, 0, -1}; | |
int solve(vector< vector< int > >& a, int x, int y) | |
{ | |
int res = 0, cur = 0; | |
int x0 = x, y0 = y; | |
bool f = false; | |
x++; | |
for(; x < 8; x++) | |
{ | |
if(a[x][y] == 2) | |
cur++; | |
if(a[x][y] == 1) | |
{ | |
f = 1; break; | |
} | |
} | |
if(f) | |
res += cur; | |
f = false, cur = 0, x = x0; | |
y++; | |
for(; y < 8; y++) | |
{ | |
if(a[x][y] == 2) | |
cur++; | |
if(a[x][y] == 1) | |
{ | |
f = 1; break; | |
} | |
} | |
if(f) | |
res += cur; | |
f = false, cur = 0, y = y0; | |
y++; x++; | |
for(; y < 8 && x < 8; y++, x++) | |
{ | |
if(a[x][y] == 2) | |
cur++; | |
if(a[x][y] == 1) | |
{ | |
f = 1; break; | |
} | |
} | |
if(f) | |
res += cur; | |
return res; | |
} | |
int main() | |
{ | |
// freopen("rsq.in", "r", stdin); | |
// freopen("rsq.out", "w", stdout); | |
ios_base::sync_with_stdio(0); | |
vector< vector< int > > a(8, vector<int>(9, 0)); // 0 - clear, 1 - Black, 2 - White | |
char c; | |
for(int i = 0; i < 8; i++) | |
for(int j = 0; j < 8; j++) | |
{ | |
cin >> c; | |
if(c == 'B') | |
a[i][j] = 1; | |
else if(c == 'W') | |
a[i][j] = 2; | |
} | |
for(int i = 0; i < 8; i++) | |
{ | |
for(int j = 0; j < 8; j++) | |
cout << a[i][j] << " "; | |
cout << endl; | |
} | |
int s = 0; | |
for(int i = 0; i < 8; i++) | |
for(int j = 0; j < 8; j++) | |
if(a[i][j] == 1) | |
s += solve(a, i, j); | |
cout << "S -> " << s << endl; | |
int mx = s; | |
for(int i = 0; i < 8; i++) | |
for(int j = 0; j < 8; j++) | |
if(a[i][j] == '0') | |
mx = max(mx, s + solve(a, i, j)); | |
cout << mx << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment