【BZOJ 2252】 矩阵距离
【题目链接】
https://www.lydsy.com/JudgeOnline/problem.php?id=2252
【算法】
将所有是”1“的点入队,然后广度优先搜索,即可
【代码】
#include<bits/stdc++.h>
using namespace std;
#define MAXN 1010 const int dx[] = {,,-,};
const int dy[] = {-,,,}; int i,j,n,m,tx,ty;
int dist[MAXN][MAXN];
char s[MAXN][MAXN];
char val;
pair<int,int> cur;
queue< pair<int,int> > q; inline bool ok(int x,int y)
{
return x >= && x <= n && y >= && y <= m;
} int main()
{
memset(dist,,sizeof(dist));
scanf("%d%d",&n,&m);
for (i = ; i <= n; i++) scanf("%s",s[i]+);
for (i = ; i <= n; i++)
{
for (j = ; j <= m; j++)
{
if (s[i][j] == '')
{
q.push(make_pair(i,j));
dist[i][j] = ;
}
}
}
while (!q.empty())
{
cur = q.front();
q.pop();
for (i = ; i < ; i++)
{
tx = cur.first + dx[i];
ty = cur.second + dy[i];
if (ok(tx,ty) && dist[tx][ty] == -)
{
dist[tx][ty] = dist[cur.first][cur.second] + ;
q.push(make_pair(tx,ty));
}
}
}
for (i = ; i <= n; i++)
{
for (j = ; j <= m; j++)
{
printf("%d ",dist[i][j]);
}
printf("\n");
} return ; }
【BZOJ 2252】 矩阵距离的更多相关文章
- BZOJ 2252 矩阵距离
BFS. #include<iostream> #include<cstdio> #include<cstring> #include<algorithm&g ...
- Bzoj 2252: [2010Beijing wc]矩阵距离 广搜
2252: [2010Beijing wc]矩阵距离 Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 563 Solved: 274[Submit][ ...
- BZOJ 2252: [2010Beijing wc]矩阵距离
题目 2252: [2010Beijing wc]矩阵距离 Time Limit: 10 Sec Memory Limit: 256 MB Description 假设我们有矩阵,其元素值非零即1 ...
- BZOJ2252: [2010Beijing wc]矩阵距离
题解: 我脑子里都是翔??? bfs一下就行了 我居然还想什么kd tree!真是too naive,,, #include<cstdio> #include<cstdlib> ...
- 「CH2501」 矩阵距离 解题报告
CH2501 矩阵距离 描述 给定一个N行M列的01矩阵 A,\(A[i][j]\) 与 \(A[k][l]\) 之间的曼哈顿距离定义为: \(dist(A[i][j],A[k][l])=|i-k|+ ...
- bzoj 2252 [ 2010 Beijing wc ] 矩阵距离 —— 多源bfs
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2252 又没能自己想出来... 一直在想如何从每个1开始广搜更新答案,再剪剪枝,什么遇到1就不 ...
- [BZOJ 2738] 矩阵乘法 【分块】
题目链接:BZOJ - 2738 题目分析 题目名称 “矩阵乘法” 与题目内容没有任何关系..就像VFK的 A+B Problem 一样.. 题目大意是给定一个矩阵,有许多询问,每次询问一个子矩阵中的 ...
- [BZOJ]1059 矩阵游戏(ZJOI2007)
虽然说是一道水题,但小C觉得还是挺有意思的,所以在这里mark一下. Description 小Q是一个非常聪明的孩子,除了国际象棋,他还很喜欢玩一个电脑益智游戏——矩阵游戏.矩阵游戏在一个N*N黑白 ...
- BZOJ.4500.矩阵(差分约束 SPFA判负环 / 带权并查集)
BZOJ 差分约束: 我是谁,差分约束是啥,这是哪 太真实了= = 插个广告:这里有差分约束详解. 记\(r_i\)为第\(i\)行整体加了多少的权值,\(c_i\)为第\(i\)列整体加了多少权值, ...
随机推荐
- ibatis知识点
1:ibatis是apache的一个开源的项目,是一个O/R mapping解决方案,优点,小巧,灵活.2:搭建环境:导入ibatis相关jar包,jdbc驱动包等3:配置文件: jdbc连接的属性文 ...
- 2015.12.25-2016.01.01 大论文迭代B
大论文B轮迭代,稍重前端 12.25 周五,完善摘要 12.26 周六,完善第一章 12.27 周天,完善第二章 12.28 周一,完善第三章 12.29 周二,完善第四章 12.30 周三,完善第五 ...
- Django 更新字段
Django在1.7以后的版本提供数据迁移命令,用来在修改模型中的字段,更新到数据库 1. python manager.py makemigrations 命令用来创建迁移文件版本的 2. pyth ...
- 安卓设置AttributeSet
XmlPullParser parser = getResources().getXml(R.layout.textview); AttributeSet attributes = Xml.as ...
- Appium 使用android_uiautomator定位元素时报错: The requested resource could not be found, or a request was received using an HTTP method that is not supported by the mapped resource
使用 android_uiautomator 定位元素时(现在用的还不太熟,对于这个方法还需要加深了解)报错: 报错信息:The requested resource could not be fou ...
- jquery 实现 单选框点击取消
<label for="1" class="z-label"> <input type="radio" class=&qu ...
- Appium 教您完美win10安装Appium1.7.2支持win客户端自动化
参考内容: https://testerhome.com/topics/10193https://testerhome.com/topics/8223https://testerhome.com/to ...
- uva10082 WERTYU (Uva10082)
A common typing error is to place the hands on the keyboard one row to the right of the correct posi ...
- (38)Spring Boot分布式Session状态保存Redis【从零开始学Spring Boot】
[本文章是否对你有用以及是否有好的建议,请留言] 在使用spring boot做负载均衡的时候,多个app之间的session要保持一致,这样负载到不同的app时候,在一个app登录之后,而访问到另外 ...
- 手动扩栈#pragma comment(linker, "/STACK:1024000000,1024000000")
#pragma comment(linker, "/STACK:1024000000,1024000000")