Untitled
unknown
plain_text
a year ago
2.1 kB
12
Indexable
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
class MapAnalyzer {
private:
int n;
vector<vector<int>> map;
vector<int> v;
vector<int> re_v;
public:
void init(int N, vector<vector<int>>& mMap) {
n = N;
map = mMap;
v.clear();
re_v.clear();
}
int numberOfCandidate(int M, int mStructure[5]) {
if(M == 1) return n*n;
int cnt = 0;
bool check_vertical, check_horizontal;
for(int i = 0; i < M; i++) {
v.push_back(mStructure[i]);
re_v.push_back(mStructure[M-i-1]);
}
for(int i = 0; i < n; i++) {
for(int j = 0; j < n; j++) {
check_horizontal = true;
check_vertical = true;
// Check horizontal shape
if (j + M - 1 < n) {
for (int k = 0; k < M-1; k++) {
if (map[i][j+k] + v[k] != map[i][j+k+1] + v[k+1] && map[i][j+k] + re_v[k] != map[i][j+k+1] + re_v[k+1]) {
check_horizontal = false;
break;
}
}
if (check_horizontal) cnt++;
}
// Check vertical shape
if (i + M - 1 < n) {
for (int k = 0; k < M-1; k++) {
if (map[i+k][j] + v[k] != map[i+k+1][j] + v[k+1] && map[i+k][j] + re_v[k] != map[i+k+1][j] + re_v[k+1]) {
check_vertical = false;
break;
}
}
if (check_vertical) cnt++;
}
}
}
return cnt;
}
};
int main() {
freopen("sample_input.txt", "r", stdin);
int n;
cin >> n;
vector<vector<int>> map(n, vector<int>(n));
for(int i = 0; i < n; i++) {
for(int j = 0; j < n; j++) {
cin >> map[i][j];
}
}
MapAnalyzer analyzer;
analyzer.init(n, map);
int mStructure[3] = {1, 1, 1};
cout << analyzerEditor is loading...
Leave a Comment