标签:
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
class GogoXCake {
public:
string solve( vector <string> cake, vector <string> cutter ) {
int m = cutter.size(), n = cutter[0].size();
for (int i = 0; i + m <= cake.size(); ++i) {
for (int j = 0; j + n <= cake[0].size(); ++j) {
bool canUse = true;
for (int x = 0; x < m; ++x)
for (int y = 0; y < n; ++y)
if (cutter[x][y] == ‘.‘ && cake[i + x][j + y] == ‘X‘)
canUse = false;
if (canUse) {
for (int x = 0; x < m; ++x)
for (int y = 0; y < n; ++y)
if (cutter[x][y] == ‘.‘)
cake[i + x][j + y] = ‘X‘;
}
}
}
for (int i = 0; i < cake.size(); ++i)
for (int j = 0; j < cake[0].size(); ++j)
if (cake[i][j] == ‘.‘)
return "NO";
return "YES";
}
};
#include <bits/stdc++.h>
using namespace std;
const int N = 55;
bool g[N][N];
class GogoXMarisaKirisima {
public:
int solve(vector <string> choices) {
int n = choices.size();
for (int i = 0; i < n; ++i) {
g[i][i] = 1;
for (int j = 0; j < n; ++j)
if (choices[i][j] == ‘Y‘) g[i][j] = 1;
}
for (int k = 0; k < n; ++k)
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j)
g[i][j] |= g[i][k] & g[k][j];
if (!g[0][n - 1]) return 0;
int ans = 0;
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j)
if (choices[i][j] == ‘Y‘ && g[0][i] && g[j][n - 1]) ++ans;
for (int i = 1; i < n - 1; ++i)
if (g[0][i] && g[i][n - 1]) --ans;
return ans;
}
};
标签:
原文地址:http://blog.csdn.net/mlzmlz95/article/details/46318745