Untitled
unknown
plain_text
a year ago
2.9 kB
13
Indexable
#include <iostream>
#include <unordered_map>
#include <cstring>
#include <string>
#include <list>
#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];
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++) {
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) {
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
if(check && cnt == 7) {
for(int r = i; r < i + 5; r++) {
for(int c = j; c < j + 5; c++) {
visit[r][c] = step;
// Tạo các chuỗi tương ứng với 4 hướng
s0 += to_string(mat[r][c]); // Hướng ban đầu
s180 += to_string(mat[i + 4 - (r - i)][j + 4 - (c - j)]); // 180 độ
s90 += to_string(mat[i + 4 - (c - j)][j + (r - i)]); // 90 độ
s270 += to_string(mat[i + (c - j)][j + 4 - (r - i)]); // 270 độ
}
}
// Đưa chuỗi vào map sau khi tạo hoàn chỉnh
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++;
}
}
}
// In ra kết quả của hash map
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;
}
int main() {
// Bạn có thể thêm phần mã thử nghiệm tại đây nếu cần
return 0;
}
Editor is loading...
Leave a Comment