社区讨论

ABC348D求hack,悬2关

学术版参与者 2已保存回复 1

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
1 条
当前快照
1 份
快照标识符
@luo7cxxa
此快照首次捕获于
2024/04/06 22:41
2 年前
此快照最后确认于
2024/04/07 14:09
2 年前
查看原帖
WA了3个点,thx
CPP
#include <bits/stdc++.h>
using namespace std;
const int N = 205, V = 2e6 + 5;
const int inf = 0x3f3f3f3f, mod = 1e9 + 7;
inline int read() {
	int f = 1, x = 0;
	char ch = getchar();
	while (ch < '0' || ch > '9') {
		if (ch == '-')f = -1;
		ch = getchar();
	}
	while (ch >= '0' && ch <= '9') {
		x = (x << 1) + (x << 3) + ch - 48;
		ch = getchar();
	}
	return f * x;
}
int n, m, sx, sy, tx, ty, q;
int a[N][N];
bool mp[N][N];
struct node {
	int x, y, w;
};
bool vis[N][N];
int walk[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
void bfs() {
	queue<node>q;
	if (a[sx][sy] > 0)q.push(node{sx, sy, a[sx][sy]});
	else {
		if(sx==tx&&sy==ty)printf("Yes");
		else printf("No");
		exit(0); 
	}
	int cnt = 0;
	while (!q.empty()) {
		cnt++;
		node now = q.front();
		q.pop();
		int nx = now.x, ny = now.y, nw = now.w;
		if (nx == tx && ny == ty && nw >= 0) {
			printf("Yes");
			exit(0);
		}
		if (nx <= 0 || nx > n || ny <= 0 || ny > m || !nw)continue;
		if (vis[nx][ny] || mp[nx][ny])continue;
		vis[nx][ny] = 1;
	//	cout << nx << ' ' << ny << ' ' << nw << "\n";
		for (int i = 0; i < 4; i++) {
			int nxx = nx + walk[i][0], nyy = ny + walk[i][1];
			if (mp[nxx][nyy])continue;
			if (a[nxx][nyy] > nw)q.push(node{nxx, nyy, a[nxx][nyy]});
			else if (nw >= 1)q.push(node{nxx, nyy, nw - 1});
		}
	}
	printf("No");
}
int main() {
	n = read(), m = read();
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			char ch;
			cin >> ch;
			if (ch == 'S')sx = i, sy = j;
			else if (ch == 'T')tx = i, ty = j;
			else if (ch == '#')mp[i][j] = 1;
		}
	}
	q = read();
	for (int i = 1; i <= q; i++) {
		int x = read(), y = read(), z = read();
		a[x][y] = z;
	}
	bfs();
	return 0;
}
/*
.3#..
.1##.
5##T.
.....
*/
/*
3.5.
#.1#
#1..
..#T
*/

回复

1 条回复,欢迎继续交流。

正在加载回复...