网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

CF35CFireAgain-创新互联

知识点:广搜

"热情、务实、专业、创新”我们不忘初心,砥砺前行,实在做人,认真做事,始终如一的专注企业互联网品牌建设与网络营销推广服务。成都品牌网站建设本着让客户满意的目标,帮助企业通过互联网创造价值.创新互联公司全体员工将通过不懈努力,力争成为客户在信息化领域中值得长期信赖的合作伙伴。

难度:5

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

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

#includeusing 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() {
	queueq;
	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;
}

你是否还在寻找稳定的海外服务器提供商?创新互联www.cdcxhl.cn海外机房具备T级流量清洗系统配攻击溯源,准确流量调度确保服务器高可用性,企业级服务器适合批量采购,新人活动首月15元起,快前往官网查看详情吧


分享题目:CF35CFireAgain-创新互联
浏览路径:http://bjjierui.cn/article/dgpidd.html

其他资讯