Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
123369 Zemu 封闭面积问题 C++ 通过 100 0 MS 248 KB 1142 2024-01-22 21:38:30

Tests(10/10):


#include <bits/stdc++.h> using namespace std; const int N = 12; int a[N][N], b[N][N]; int dx[4] = {1, -1, 0, 0}; int dy[4] = {0, 0, 1, -1}; void dfs_iterative(int sx, int sy) { stack<pair<int, int>> s; s.push({sx, sy}); while (!s.empty()) { int x = s.top().first; int y = s.top().second; s.pop(); if (x < 0 || x >= N || y < 0 || y >= N || a[x][y] != 0) continue; a[x][y] = 1; for (int i = 0; i < 4; ++i) { int nx = x + dx[i]; int ny = y + dy[i]; if (nx >= 0 && nx < N && ny >= 0 && ny < N && a[nx][ny] == 0) { s.push({nx, ny}); } } } } int main() { memset(a, 0, sizeof(a)); for (int i = 1; i <= 10; i++) { for (int j = 1; j <= 10; j++) { cin >> b[i][j]; if (b[i][j]) a[i][j] = 2; } } dfs_iterative(0, 0); int sum = 0; for (int i = 1; i <= 10; i++) { for (int j = 1; j <= 10; j++) { if (a[i][j] == 0) sum++; } } cout << sum << endl; return 0; }


测评信息: