Untitled
unknown
plain_text
a year ago
1.6 kB
16
Indexable
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int n, map[20][20];
vector<int>v;
vector<int>re_v;
void init(int N, int mMap[20][20])
{
/*
n = N;
for(int i=0; i<N; i++)
for(int j=0; j<N; j++)
map[i][j] = mMap[i][j];*/
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_hozion;
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_hozion = true;
check_vertical = true;
//Check hinh hozion
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_hozion = false;
break;
}
}
//Check hinh vertical
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_hozion) cnt++;
if(check_vertical) cnt++;
}
}
return cnt;
}
//int maxArea(int M, int mStructure[5], int mSeaLevel)
//{
// return 0;
//}
int main() {
freopen("sample_input.txt", "r", stdin);
// 6 1 2 1 5 5 5 3 1 3 1 1 5 1 4 5 5 5 5 2 1 1 1 4 5 1 4 5 5 5 5 3 2 3 4 1 2
cin>>n;
for(int i=0; i<n; i++) {
for(int j=0;j<n; j++) {
cin>>map[i][j];
}
}
init(6, map);
int mStructure[3] = {1,1,1};
cout<<numberOfCandidate(3, mStructure);
return 0;
}Editor is loading...
Leave a Comment