CodeForces 616C The Labyrinth
先预处理出所有连通块,对于每一个*,看他四周的连通块即可
#include<cstdio>
#include<cstring>
#include<queue>
#include<algorithm>
using namespace std; const int maxn=+;
char s[maxn][maxn];
int Map[maxn][maxn];
int n,m;
int dir[][];
int Belong[maxn*maxn];//每个点属于哪个联通快
int tot[maxn*maxn];//每个联通快有几个点
int Block;
int TT;
int tmp[];
int RT[maxn*maxn]; void DFS(int x,int y)
{
Map[x][y]=Block; TT++;
for(int i=;i<;i++)
{
int NewX=x+dir[i][];
int NewY=y+dir[i][];
if(NewX>=&&NewX<=n-)
if(NewY>=&&NewY<=m-)
if(Map[NewX][NewY]==)
DFS(NewX,NewY);
}
} int P(int x,int y)
{
if(x>=&&x<=n-)
if(y>=&&y<=m-)
return ;
return ;
} int main()
{
dir[][]=;dir[][]=;
dir[][]=;dir[][]=;
dir[][]=-;dir[][]=;
dir[][]=;dir[][]=-; scanf("%d%d",&n,&m);
memset(Map,,sizeof Map);
for(int i=;i<n;i++) scanf("%s",s[i]);
Block=;
for(int i=;i<n;i++)
for(int j=;j<m;j++)
{
if(s[i][j]=='*') Map[i][j]=-;
else Map[i][j]=;
} for(int i=;i<n;i++)
for(int j=;j<m;j++)
{
if(Map[i][j]==)
{
TT=;
DFS(i,j);
tot[Block]=TT;
Block++;
}
} for(int i=;i<n;i++)
{
for(int j=;j<m;j++)
{
if(s[i][j]=='*')
{
int ans=;
int tmp[],xx=;
if(P(i-,j)) tmp[xx++]=Map[i-][j];
if(P(i+,j)) tmp[xx++]=Map[i+][j];
if(P(i,j-)) tmp[xx++]=Map[i][j-];
if(P(i,j+)) tmp[xx++]=Map[i][j+];
for(int r=;r<xx;r++)
{
int fail=;
for(int d=;d<r;d++) if(tmp[r]==tmp[d]) fail=;
if(!fail) ans=ans+tot[tmp[r]];
}
ans++;
ans=ans%;
s[i][j]=ans+'';
}
}
} for(int i=;i<n;i++) printf("%s\n",s[i]);
return ;
}
CodeForces 616C The Labyrinth的更多相关文章
- CodeForces - 616C(很有意思的bfs,set,map的使用)
传送门: http://codeforces.com/problemset/problem/616/C C. The Labyrinth time limit per test 1 second me ...
- [Codeforces Round #516][Codeforces 1063B/1064D. Labyrinth]
题目链接:1063B - Labyrinth/1064D - Labyrinth 题目大意:给定一个\(n\times m\)的图,有若干个点不能走,上下走无限制,向左和向右走的次数分别被限制为\(x ...
- Codeforces 1064 D - Labyrinth
D - Labyrinth 对于位置(i,j), j - c = R - L = const(常数), 其中R表示往右走了几步,L表示往左走了几步 所以R越大, L就越大, R越小, L就越小, 所以 ...
- Codeforces 1064D/1063B Labyrinth
原题链接/原题链接(代理站) 题目翻译 给你一个\(n*m\)的迷宫和起始点,有障碍的地方不能走,同时最多向左走\(x\)次,向右走\(y\)次,向上向下没有限制,问你有多少个格子是可以到达的. 输入 ...
- [ CodeForces 1063 B ] Labyrinth
\(\\\) \(Description\) 给出一个四联通的\(N\times M\) 网格图和起点.图中有一些位置是障碍物. 现在上下移动步数不限,向左至多走 \(a\) 步,向右至多走 \(b\ ...
- 【Codeforces 1063B】Labyrinth
[链接] 我是链接,点我呀:) [题意] 你可以往左最多x次,往右最多y次 问你从x,y出发最多能到达多少个格子 只能往上下左右四个方向走到没有障碍的格子 [题解] 假设我们从(r,c)出发想要到固定 ...
- Educational Codeforces Round 5
616A - Comparing Two Long Integers 20171121 直接暴力莽就好了...没什么好说的 #include<stdlib.h> #include&l ...
- CSU-ACM2018暑假集训6—BFS
可以吃饭啦!!! A:连通块 ZOJ 1709 Oil Deposits(dfs,连通块个数) B:素数变换 打表+bfs POJ 3216 Prime Path(打表+bfs) C:水bfs HDU ...
- Codeforces Educational Codeforces Round 5 C. The Labyrinth 带权并查集
C. The Labyrinth 题目连接: http://www.codeforces.com/contest/616/problem/C Description You are given a r ...
随机推荐
- mysql 常用命令集锦[绝对精华]
一.连接MYSQL. 格式: mysql -h主机地址 -u用户名 -p用户密码 1.连接到本机上的MYSQL. 首先打开DOS窗口,然后进入目录mysql\bin,再键入命令mysql -u roo ...
- bind启动时提示953端口被使用
部署DNS的时候遇到个奇葩的问题,总是提示 couldn't add command channel 0.0.0.0#953: address in use 实际上系统上并没有进程使用953端口.查询 ...
- 未能加载文件或程序集“ICSharpCode.SharpZipLib, Version=0.86.0.518, Culture=neutral, PublicKeyToken=1b03e6acf1164f73”或它的某一个依赖项
未能加载文件或程序集“ICSharpCode.SharpZipLib, Version=0.86.0.518, Culture=neutral, PublicKeyToken=1b03e6acf116 ...
- centos7 python
yum -y install gcc cd /usr/local/src wget https://www.python.org/ftp/python/3.6.0/Python-3.6.0a1 ...
- 【kmp】 字符串最大周期
大侠住店 TimeLimit: 1 Second MemoryLimit: 32 Megabyte Totalsubmit: 116 Accepted: 64 Description 有一天晚上,一位 ...
- Win32串口API
在工业控制中,工控机(一般都基于Windows平台)经常需要与智能仪表通过串口进行通信.串口通信方便易行,应用广泛. 一般情况下,工控机和各智能仪表通过RS485总线进行通信.RS485的通信方式是半 ...
- swool安装
swoole安装 安装完PHP后,即可安装swoole扩展. swoole扩展下载地址:https://github.com/swoole/swoole-src/releases 尽量选择stable ...
- U盘安装Centos后拔除U盘无法启动问题解决方法
今天安装CentOS后发现把引导文件安装在U盘上了,所以不插U盘就无法进入CentOS系统,在网上找到这种方法成功摆脱U盘启动,避免重新用U盘做引导盘安装系统,简单省事,所以发个帖,留着以后备用. 1 ...
- 【转载】关于SetWindowOrgEx、SetViewportOrgEx、SetViewportExtEx 和SetWindowExtEx 详解
关于SetWindowOrgEx.SetViewportOrgEx.SetViewportExtEx 和SetWindowExtEx 详解 1. SetWindowOrgEx是设置窗口的原点坐标. ...
- Sea.Js使用入门
1.Sea.Js是什么 seajs相对于RequireJs与LabJS就比较年轻,2010年玉伯发起了这个开源项目,SeaJS遵循CMD规范,与RequireJS类似,同样做为模块加载器.示例 // ...