先预处理出所有连通块,对于每一个*,看他四周的连通块即可

#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的更多相关文章

  1. CodeForces - 616C(很有意思的bfs,set,map的使用)

    传送门: http://codeforces.com/problemset/problem/616/C C. The Labyrinth time limit per test 1 second me ...

  2. [Codeforces Round #516][Codeforces 1063B/1064D. Labyrinth]

    题目链接:1063B - Labyrinth/1064D - Labyrinth 题目大意:给定一个\(n\times m\)的图,有若干个点不能走,上下走无限制,向左和向右走的次数分别被限制为\(x ...

  3. Codeforces 1064 D - Labyrinth

    D - Labyrinth 对于位置(i,j), j - c = R - L = const(常数), 其中R表示往右走了几步,L表示往左走了几步 所以R越大, L就越大, R越小, L就越小, 所以 ...

  4. Codeforces 1064D/1063B Labyrinth

    原题链接/原题链接(代理站) 题目翻译 给你一个\(n*m\)的迷宫和起始点,有障碍的地方不能走,同时最多向左走\(x\)次,向右走\(y\)次,向上向下没有限制,问你有多少个格子是可以到达的. 输入 ...

  5. [ CodeForces 1063 B ] Labyrinth

    \(\\\) \(Description\) 给出一个四联通的\(N\times M\) 网格图和起点.图中有一些位置是障碍物. 现在上下移动步数不限,向左至多走 \(a\) 步,向右至多走 \(b\ ...

  6. 【Codeforces 1063B】Labyrinth

    [链接] 我是链接,点我呀:) [题意] 你可以往左最多x次,往右最多y次 问你从x,y出发最多能到达多少个格子 只能往上下左右四个方向走到没有障碍的格子 [题解] 假设我们从(r,c)出发想要到固定 ...

  7. Educational Codeforces Round 5

    616A - Comparing Two Long Integers    20171121 直接暴力莽就好了...没什么好说的 #include<stdlib.h> #include&l ...

  8. CSU-ACM2018暑假集训6—BFS

    可以吃饭啦!!! A:连通块 ZOJ 1709 Oil Deposits(dfs,连通块个数) B:素数变换 打表+bfs POJ 3216 Prime Path(打表+bfs) C:水bfs HDU ...

  9. 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 ...

随机推荐

  1. Fatal error: Class ‘mysqli’ not found in解决办法

    在使用[$conn = new \mysqli($servername, $username, $password,$dbname);]连接msql数据库的时候 出现错误:[Fatal error: ...

  2. CLR 无法从 COM

    上下文 0x50ece80 转换为 COM 上下文 0x50ecf38,这种状态已持续 60 秒.拥有目标上下文/单元的线程很有可能执行的是非泵式等待或者在不发送 Windows 消息的情况下处理一个 ...

  3. PCI源码学习笔记

    这个是PCI的关键结构体. static const struct file_operations proc_bus_pci_operations = { .owner = THIS_MODULE, ...

  4. Django CRM学员系统项目

    项目需求: 1.分讲师\学员\课程顾问角色,2.学员可以属于多个班级,学员成绩按课程分别统计3.每个班级至少包含一个或多个讲师4.一个学员要有状态转化的过程 ,比如未报名前,报名后,毕业老学员5.客户 ...

  5. Android 获取 AudioRecord 麦克风音量大小并做选择性发送

    extends:http://blog.csdn.net/alvinhuai/article/details/8955127,http://mikespook.com/2010/11/android- ...

  6. 利用npoi把多个DataTable导入Excel多个sheet中

    { 题外拓展:把datatable插入dataset DataTable fuben = new DataTable();//定义的datatablefuben = table.Tables[0].C ...

  7. (UE4) 动态加载DLL

    目前还没有实现,实在搞不懂为什么,大概代码如下: //------------------------------------------------------------------------- ...

  8. 1988: Sn 爆long long 的处理方法

    题目描述 给你两个数 n, p(0 < n,p <= 10^15); a1 = 1;  a2 = 1+2;  a3 = 1+2+3;  ... an = 1+2+3+...+n    Sn ...

  9. setter getter 属性 点语法

    转载自:http://liuyafang.blog.51cto.com/8837978/1543715 什么时setter,getter, 在OC里, 为实例变量赋zhi的方法称作setter(设置器 ...

  10. 基础-JavaScript中的事件

    在html中引入外部js方式: <html> <head> <script src="xxx.js"></script> </ ...