求条啊
查看原帖
求条啊
1023732
FlowerAccepted楼主2024/12/8 14:43

超时4个点求条:

QAQQWQ
SampleAC×3\colorbox{00CC00}{\color{white}{AC}} \times 3
AllAC×35TLE×4\colorbox{00CC00}{\color{white}{AC}} \times 35\\ \colorbox{FFCC00}{\color{white}{TLE}} \times 4
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;

vector<pair<int, int> > v;
char a[1005][1005];
bool vis[1005][1005];
int ans = 0, h, w, d,
stored[1005][1005],
dx[] = { 0,  0, 1, -1},
dy[] = { 1, -1, 0,  0};

void dfs(int x, int y, int d) {
    stored[x][y] = max(stored[x][y], d);
    if (!vis[x][y]) {
        ans ++;
        vis[x][y] = 1;
    }
    if (d == 0) {
        return;
    }
    for (int i = 0; i < 4; i ++) {
        if (a[x + dx[i]][y + dy[i]] == '.' &&
            (stored[x + dx[i]][y + dy[i]] < d - 1 || !stored[x + dx[i]][y + dy[i]])) {
            dfs(x + dx[i], y + dy[i], d - 1);
        }
    }
}

int main() {
    cin >> h >> w >> d;
    for (int i = 1; i <= h; i ++) {
        for (int j = 1; j <= w; j ++) {
            cin >> a[i][j];
            if (a[i][j] == 'H') {
                v.push_back(make_pair(i, j));
            }
        }
    }
    for (auto i : v) {
        dfs(i.first, i.second, d);
    }
    cout << ans;
    return 0;
}

另附:抢到了本题第一个帖子

2024/12/8 14:43
加载中...