CF35C Fire Again

知识点:广搜

难度:5

这个题给的难度5实际是虚高了,顶多是个绿题,CF的分是1500,还是比较准确的,这个就是一个裸的bfs,是个多源的bfs,然后我们广搜的时候每次出队的时候更新一下答案就行了,那么最后一定是最后才覆盖的点

然后就是这个题是啥标准输入输出啥的,需要在程序里面加上那个玩意儿,这个我记得学c语言的时候用到了,但是现在已经往的差不多了

#include <bits/stdc++.h>

using namespace std;

const int N = 2005;

struct node {
	int x, y;
	node() {}
	node(int a, int b): x(a), y(b) {}
} ans;

int n, m, k, a[10], b[10], dist[N][N];
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, 1, 0, -1};

void bfs() {
	queue<node> q;
	memset(dist, -1, sizeof(dist));
	for (int i = 0; i < k; i++) {
		q.push(node(a[i], b[i]));
		dist[a[i]][b[i]] = 0;
	}
	while (!q.empty()) {
		node now = q.front(); q.pop();
		ans = now;
		for (int i = 0; i < 4; i++) {
			int x1 = now.x + dx[i];
			int y1 = now.y + dy[i];
			if (x1 < 1 || x1 > n || y1 < 1 || y1 > m) continue;
			if (dist[x1][y1] == -1) {
				q.push(node(x1, y1));
				dist[x1][y1] = dist[now.x][now.y] + 1;
			}
		}
	}
}

int main() {
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	cin >> n >> m >> k;
	for (int i = 0; i < k; i++) {
		cin >> a[i] >> b[i];
	}
	bfs();
	cout << ans.x << " " << ans.y;
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值