You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

101 lines
2.7 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#include <bits/stdc++.h>
using namespace std;
int main() {
//输入+输出重定向
freopen("../1349.in", "r", stdin);
freopen("../1349.out", "w", stdout);
//行15列10
const int N = 15, M = 10, SIZE = 4;
//原有的模块图案
int source[N][M] = {0};
//为了回退加的数组
int tmp[N][M] = {0};
//结果
int target[N][M] = {0};
int blank[N][M] = {0};
//读取初始化数据
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++) {
cin >> source[i][j];
}
}
//小方块
int small[SIZE][SIZE] = {0};
for (int i = 0; i < SIZE; i++) {
for (int j = 0; j < SIZE; j++) {
cin >> small[i][j];
}
}
//将小方块扩展到大模块图案一样大即填充0解决
int p;
cin >> p;
for (int i = 0; i < SIZE; ++i) {
for (int j = 0; j < SIZE; ++j) {
blank[i][j + p - 1] = small[i][j];
}
}
//开始错行叠加
for (int i = 0; i < N; i++) {
//叠加
for (int i = 0; i < N; ++i) {
for (int j = 0; j < M; ++j) {
tmp[i][j] = blank[i][j] + source[i][j];
}
}
//检查
bool success = true;
for (int i = 0; i < N; ++i) {
for (int j = 0; j < M; ++j) {
if (tmp[i][j] > 1) {
success = false;
break;
}
}
}
if (success) {
//数组复制出来,可能是最终的解
memcpy(target,tmp,sizeof(target));
//每次错一行
//如果方块的本行和大于0就不能再继续了~
int sum = 0;
for (int j = 0; j < M; ++j) {
sum += blank[i][j];
}
if (sum > 0) {
break;
} else {
//删除尾行并且在首行增加一行0
int newBlank[N][M] = {0};
for (int i = 0; i < N - 1; i++) {
for (int j = 0; j < M; ++j) {
newBlank[i + 1][j] = blank[i][j];
}
}
//拷贝回去,完成预定目标
memcpy(blank,newBlank,sizeof(blank));
}
} else {
break;
}
}
//输出结果
for (int i = 0; i < N; ++i) {
for (int j = 0; j < M; ++j) {
cout << target[i][j] << " ";
}
cout << endl;
}
//关闭文件
fclose(stdin);
fclose(stdout);
return 0;
}