diff --git a/AcWing/378/378.cpp b/AcWing/378/378.cpp new file mode 100644 index 00000000..9a582df1 --- /dev/null +++ b/AcWing/378/378.cpp @@ -0,0 +1,64 @@ +#include +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 105; +const int dx[] = {2, 2, -2, -2, 1, 1, -1, -1}, + dy[] = {1, -1, 1, -1, 2, -2, 2, -2}; + +int n, m, t, ans; +std::pair match[N][N]; +bool disabled[N][N], vis[N][N]; + +bool dfs(int x, int y) { + for (int i = 0; i < 8; i++) { + int xx = x + dx[i], + yy = y + dy[i]; + + if (xx < 1 || xx > n || yy < 1 || yy > m) continue; + if (disabled[xx][yy] || vis[xx][yy]) continue; + + vis[xx][yy] = true; + + auto t = match[xx][yy]; + + if (!t.first || dfs(t.first, t.second)) { + match[xx][yy] = std::make_pair(x, y); + return true; + } + } + + return false; +} + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + cin >> n >> m >> t; + + for (int i = 1; i <= t; i++) { + int x, y; + + cin >> x >> y; + + disabled[x][y] = true; + } + + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= m; j++) { + if (disabled[i][j] || (i + j) % 2) continue; + + memset(vis, 0x00, sizeof(vis)); + if (dfs(i, j)) ans++; + } + } + + cout << n * m - t - ans << endl; + + return 0; +} diff --git a/AcWing/378/data/1.ans b/AcWing/378/data/1.ans new file mode 100644 index 00000000..bdfe133b --- /dev/null +++ b/AcWing/378/data/1.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:84b9399ba1ce23f356e882a473805faf9794dc028784335029fadc1a74909339 +size 5 diff --git a/AcWing/378/data/1.in b/AcWing/378/data/1.in new file mode 100644 index 00000000..02621696 --- /dev/null +++ b/AcWing/378/data/1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:acff48b3081e258705f62a29ac1ed5759ef453840dc38616b57f53b1029c1059 +size 20