水题,P1789 【Mc生存】插火把 (暴力即可)
#include<cstdio> #define maxn int(1e4) bool dp[maxn][maxn]; int n; void f1(int x, int y) { dp[x][y] = 1; int i = x + 1, j = y; int k = 0; while (1) { ++k; if (i > 0 && i <= n&&j > 0 && j <= n)dp[i][j] = 1; if (k == 1 || k == 4)++j; else --j; if (k == 1 || k == 2)--i; else ++i; if (i == x + 1 && j == y)break; } i = x + 2; j = y; k = 0; while (1) { ++k; if (i > 0 && i <= n&&j > 0 && j <= n)dp[i][j] = 1; if (k ==1||k==2||k==7||k==8)++j; else --j; if (k == 5 || k == 6 || k == 7 || k == 8)++i; else --i; if (i == x + 2 && j == y)break; } } void f2(int x, int y) { for (int i = x - 2; i <= x + 2;++i) for (int j = y - 2; j <= y + 2;++j) if (i > 0 && i <= n&&j > 0 && j <= n)dp[i][j] = 1; } int main() { int k, t; scanf("%d%d%d", &n, &k, &t); for (int i = 0; i < k; ++i) { int x, y; scanf("%d%d", &x, &y); f1(y, x); } for (int i = 0; i < t; ++i) { int x, y; scanf("%d%d", &x, &y); f2(y, x); } int ans = 0; // for (int i = 1; i <= n; ++i) // { // for (int j = 1; j <= n; ++j) // if (dp[i][j])printf("*"); // else printf("."); // printf("\n"); // } for (int i = 1; i <= n;++i) for (int j = 1; j <= n;++j) if (!dp[i][j])++ans; printf("%d\n", ans); }