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 ...
随机推荐
- oomph
http://blog.csdn.net/u011004037/article/details/45679573 这么好个功能起了这么操蛋个名字害得老子一直不知道他干啥的
- STM32F407的硬件I2C
源:STM32F407的硬件I2C 我使用的是STM32的固件库. 硬件模块使用之前必须配置其参数,I2C的配置如下: void IIC_Config(void) { GPIO_InitTypeDef ...
- asp之FSO大全
<%Function ShowDriveInfo(strFolder)'显示磁盘信息'strRootFolder="/"'strDrivInfo=ShowDriveInfo( ...
- 【转】VC6.0打开或者添加工程文件崩溃的解决方法
很多学习编程的同学都遇到这样的问题,在Windows操作系统下使用Visual C++ 6.0编程时,如果点击菜单中的[打开]或者[添加],或者按快捷键,都会弹出下图的对话框,出现程序崩溃并退出的情况 ...
- Android自定义XML属性
<?xml version="1.0" encoding="utf-8"?> <resources> <declare-style ...
- Gson解析数据
package com.bwie.test;import java.io.BufferedReader;import java.io.IOException;import java.io.InputS ...
- VideoView的视频播放
//-------------onCreate方法中----------------------- VideoView video_view = (VideoView) findViewById(R. ...
- android 垂直 SeekBar 源代码(VerticalSeekBar)[转]
主要是继承 AbsSeekBar 然后修改下面这些方法 onProgressRefresh() //当进度条数据更新的时候,例如我们拖动滑动条的时候,这个方法被调用 setThumbPos() //这 ...
- FZU 2140 Forever 0.5(将圆离散化)
主要就是将圆离散化,剩下的都好办 #include<iostream> #include<cstdio> #include<cstring> #include< ...
- poj 1654 Area(计算几何--叉积求多边形面积)
一个简单的用叉积求任意多边形面积的题,并不难,但我却错了很多次,double的数据应该是要转化为long long,我转成了int...这里为了节省内存尽量不开数组,直接计算,我MLE了一发...,最 ...