大家快来看看Meteor Shower S的离谱翻译版本(勿喷,在Vjudge上找着的)
在又一次轮回中,白厄又一次变身卡厄斯兰那,即将释放地爆天星,毁灭一切黑潮造物(以及整个翁法罗斯)。而你,盗火行者(对,你就是那个盗火行者)眀白接下来会发生什么,你需要找到一片安全的地方,一个永远不会被地爆天星附带的陨石摧毁的地方。
将有M颗陨石(1 ≤ M ≤ 50,000)坠落,其中第i颗陨石将在时间Ti(0 ≤Ti ≤ 1,000)撞击点(Xi, Yi )(0 ≤Xi ≤300;0 ≤Yi ≤300)。流星的力量会将它所在的格子,以及周围4个相邻的格子都化为焦土,你当然也无法再在这些格子上行走。
你将在时间0从原点出发,可以在第一象限内以每秒一个距离单位的速度移动到任何尚未被流星摧毁的(通常是4个)相邻直线点。你在任何时间都不能位于被摧毁的点上。你需要知道你最少需要多少时间才能到达一个安全的格子。如果不可能到达输出-1。
输入格式
第1行:单个整数M
第2…M+1行:第i+1行包含三个用空格分隔的整数:Xi, Yi和Ti
输出格式
第1行:你到达安全地点的最短时间,如果不可能则输出-1。
样例1:
输入:4
0 0 2
2 1 2
1 1 2
0 3 5
输出:5
附
——但是卡厄斯兰那大招中的主体 大锅巴 怎么办呢?
——......好问题......
我贴个题解:
#include<bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int maxn = 1e3 + 10;
int mapp[maxn][maxn];
bool v[maxn][maxn];
struct point {
int x, y, step;
};
queue<point>q;
pair<int, int> dirs[] = {
{1, 0}, {-1, 0}, {0, 1}, {0, -1}
};
int BFS(point a) {
q.push(a);
v[a.x][a.y] = 1;
while(!q.empty()) {
point b = q.front();
q.pop();
for(auto [dx, dy] : dirs) {
point c;
c.x = b.x + dx;
c.y = b.y + dy;
c.step = b.step + 1;
if(c.x < 0 || c.y < 0)
continue;
if(mapp[c.x][c.y] == inf)
return c.step;
if(c.step < mapp[c.x][c.y] && !v[c.x][c.y]) {
q.push(c);
v[c.x][c.y] = 1;
}
}
}
return -1;
}
int main() {
cin.tie(0)->sync_with_stdio(0);
int m;
cin >> m;
memset(mapp,inf,sizeof(mapp));
for(int i = 1, x, y, t; i <= m; ++i) {
cin >> x >> y >> t;
mapp[x][y] = min(mapp[x][y], t);
for(auto [dx, dy] : dirs) {
int nx = x + dx, ny = y + dy;
if(nx == -1 || ny == -1)
continue;
mapp[nx][ny] = min(mapp[nx][ny], t);
}
}
point a;
a.x = a.y = a.step = 0;
cout << BFS(a) << endl;
}