Untitled
unknown
plain_text
a year ago
2.3 kB
9
Indexable
#include <iostream>
#include <unordered_map>
#include <map>
#include <cstring>
#include <algorithm>
#include <string>
#include <list>
#include <vector>
#define MAX_SIZE 1000
using namespace std;
int n;
int step;
unordered_map<int, list<string>> mp;
int visit[MAX_SIZE][MAX_SIZE];
int mat[MAX_SIZE][MAX_SIZE];
struct cmp{
bool operator()() {
}
};
void init(int N, int mPlane[MAX_SIZE][MAX_SIZE])
{
// Reset
mp.clear();
n = N;
step = 0;
for(int i = 0; i < n; i++) {
for(int j = 0; j < n; j++) {
mat[i][j] = mPlane[i][j];
}
}
memset(visit, 0, sizeof(visit));
// Hash map
for(int i = 0; i < n - 4; i ++) { // Sửa n-3 thành n-4 để tránh truy cập ngoài mảng
for(int j = 0; j < n - 4; j ++) {
int cnt = 0;
bool check = false;
string s0 = "", s90 = "", s180 = "", s270 = "";
for(int r = i; r < i + 5; r++) {
for(int c = j; c < j + 5; c++) {
if(mat[r][c] == 1) { // Kiểm tra toàn bộ ô trong vùng 5x5
cnt++;
if(mat[i][c] == 1 || mat[i+4][c] == 1 || mat[r][j] == 1 || mat[r][j+4] == 1) {
check = true;
}
}
}
}
// Kiểm tra điều kiện và thêm vào hash map
//cout<<"i: "<<i<<" "<<"j: "<<j<<" "<<cnt<<endl;
if(check && cnt == 7) {
for(int r = i; r < i + 5; r++) {
for(int c = j; c < j + 5; c++) {
visit[r][c] = step;
//Hozion
s0 += to_string(mat[r][c]);
s180 += to_string(mat[r][j+5-c]);
//Vertical
s90 += to_string(mat[c][r]);
s270 += to_string(mat[j+5-c][r]);
}
mp[i*N+j].push_back(s0);
mp[i*N+j].push_back(s90);
mp[i*N+j].push_back(s180);
mp[i*N+j].push_back(s270);
step++;
}
}
}
}
for (const auto &p : mp) {
std::cout << p.first << ": ";
for (const auto &s : p.second) {
std::cout << s << " ";
}
std::cout << std::endl;
}
}
int getCount(int mPiece[5][5])
{
int cnt = 0;
string temp = "";
for(int i=0; i<5; i++) {
for(int j=0; j<5; j++) {
temp += to_string(mPiece[i][j]);
}
}
for(auto it:mp) {
for(auto v:it.second) {
if(v == temp) cnt++;
}
}
return cnt;
}
int getPosition(int mRow, int mCol)
{
return 0;
}Editor is loading...
Leave a Comment