Codeforces Round #556 (Div. 2) B. Tiling Challenge
阿新 • • 發佈:2019-05-01
amp span names ons memset getchar() all clu sin
這題題目大致意思就是找它所有的.能否滿足五字格,簡單遍歷就好,直接上代碼
#include<iostream> #include<cstdio> #include<algorithm> #include<cstring> using namespace std; const int maxn = 100; char a[maxn][maxn]; int lazy[maxn][maxn]; int main() { int x; cin >> x; memset(lazy,0, sizeof(lazy)); int ans = 0; for (int i = 0; i < x; i++) { getchar(); for (int j = 0; j < x; j++) { scanf("%c", &a[i][j]); if (a[i][j] == ‘.‘) { ans++; lazy[i][j] = 1; } } }int sum = 0; for (int i = 0; i < x; i++) { for (int j = 0; j < x; j++) { if (lazy[i][j] == 0||lazy[i][j]==2)continue; if (lazy[i][j] == 1) { if (lazy[i - 1][j] == 1 && lazy[i + 1][j] == 1 && lazy[i][j - 1] == 1 && lazy[i][j + 1] == 1) { sum += 5; lazy[i][j] = 2; lazy[i - 1][j] = 2; lazy[i + 1][j] = 2; lazy[i][j + 1] = 2; lazy[i][j - 1] = 2; } } } } if (sum == ans) { printf("YES\n"); } else { printf("NO\n"); } }
Codeforces Round #556 (Div. 2) B. Tiling Challenge