1 条题解
-
0
C++代码
#include <iostream> #include <vector> using namespace std; int main() { vector<vector<int>> grid(15, vector<int>(10)); for (int i = 0; i < 15; ++i) { for (int j = 0; j < 10; ++j) { cin >> grid[i][j]; } } vector<vector<int>> block(4, vector<int>(4)); for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { cin >> block[i][j]; } } int initial_col; cin >> initial_col; initial_col--; // 转换为0-based列索引 int y = 0; while (true) { bool can_place = true; for (int dy = 0; dy < 4; ++dy) { for (int dx = 0; dx < 4; ++dx) { if (block[dy][dx] == 1) { int row = y + dy; int col = initial_col + dx; if (row < 0 || row >= 15 || col < 0 || col >= 10 || grid[row][col] == 1) { can_place = false; } } } if (!can_place) break; } if (!can_place) break; y++; } for (int dy = 0; dy < 4; ++dy) { for (int dx = 0; dx < 4; ++dx) { if (block[dy][dx] == 1) { int row = (y - 1) + dy; int col = initial_col + dx; grid[row][col] = 1; } } } for (int i = 0; i < 15; ++i) { for (int j = 0; j < 10; ++j) { cout << grid[i][j] << " "; } cout << endl; } return 0; }
信息
- ID
- 2757
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 10
- 标签
- 递交数
- 1
- 已通过
- 1
- 上传者