预处理每一个 ‘ . ’ 的块(通过上下左右相连的),用 mp 二维数组存编号,,通过这个编号 存这个块含有的 ‘ . ’ 个数

最后输出

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<stack>
#include<map>using namespace std;
typedef long long ll;
const int maxn = 1e3 + 7, INF = 0x7f7f7f7f, mod = 1e9 + 7;int n, m, num;
char s[maxn][maxn];
int mp[maxn][maxn];
bool vis[maxn][maxn];
int ans[maxn*maxn] = {0};
set<int> st;int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};void dfs(int x, int y, int id) {vis[x][y] = true; num++;mp[x][y] = id;for(int i = 0; i < 4; ++i) {int nx = x + dx[i], ny = y + dy[i];if(nx < 0 || nx >= n || ny < 0 || ny > m) continue;if(!vis[nx][ny] && s[nx][ny] == '.') {dfs(nx, ny, id);}}
}int main() {scanf("%d %d", &n, &m);for(int i = 0; i < n; ++i) {scanf("%s", s[i]);}int cnt = 1;memset(vis, false, sizeof vis);for(int i = 0; i < n; ++i) {for(int j = 0; j < m; ++j) {if(s[i][j] == '.' && !vis[i][j]) {num = 0;dfs(i, j, cnt);ans[cnt++] = num;}}}for(int i = 0; i < n; ++i) {for(int j = 0; j < m; ++j) {if(s[i][j] == '.') printf(".");else {st.clear(); int anss = 0;for(int k = 0; k < 4; ++k) {int nx = i + dx[k], ny = j + dy[k];if(nx < 0 || nx >= n || ny < 0 || ny > m) continue;if(st.count(mp[nx][ny])) continue;anss += ans[mp[nx][ny]]; st.insert(mp[nx][ny]);}cout << (anss+1)%10;}}cout << endl;}return 0;
}

CodeForces - 616C The Labyrinth dfs+暴力相关推荐

  1. ZOJ 3300 Mahjong DFS暴力解决。。

    ZJU 3300: 题目描述 就看成1-9的数字,DFS暴力搜索下就过了..... 要求输入13 个数字,声明个数组记录数字的个数,DFS 里各种回溯: #include<stdio.h> ...

  2. CodeForces 991E Bus Number DFS+ 组合数

    CodeForces 991E Bus Number DFS+ 组合数 题目大意:给定一个数字,数字里出现的每一个数,都至少要用一个,问能组成多少个新数,不加前导零. input: 2028 outp ...

  3. Codeforces9C dfs暴力

    一道水题,dfs暴力就行. #include <stdio.h>int ans = 0, num; void dfs(int n) {if(n > num)return;dfs(n ...

  4. C-木棍游戏 DFS暴力

    题目链接:C-木棍游戏_牛客小白月赛43 (nowcoder.com) #include<algorithm> #include<cstdio> #include<cst ...

  5. 【CodeForces - 616C 】The Labyrinth点石成金(并查集,dfs)

    题干: 小O无意间发现了一张藏宝图,它跟随藏宝图的指引来到了一个宫殿,宫殿的地板被分成了n*m块格子,每个格子上放置了金子或者石头 藏宝图告诉小O,它可以选择一块石头变成金子,并且带走与变化后的金子联 ...

  6. Codeforces 104C Cthulhu dfs暴力 || 点双连通缩点

    题目链接:点击打开链接 题意: 给定n个点m条边的无向图 问图中是否存在 有且仅有一个简单环和一些树,且这些树的root都在这个简单环上. 瞎写了个点双..== #include <stdio. ...

  7. 【CodeForces - 616C】The Labyrinth(bfs,并查集,STLset)

    题干: 求每个*能够到达的格子数量,只有.可以走(四个方向扩展),结果mod 10,替换 * 后输出. Input The first line contains two integers n, m  ...

  8. Codeforces 460E Roland and Rose(暴力)

    题目链接:Codeforces 460E Roland and Rose 题目大意:在以原点为圆心,半径为R的局域内选择N个整数点,使得N个点中两两距离的平方和最大. 解题思路:R最大为30.那么事实 ...

  9. CodeForces - 1354E Graph Coloring(dfs判断二分图+dp)

    题目链接:点击查看 题目大意:给出一个由 n 个点和 m 条边组成的无向图,要求给 n 个点赋值为 1 . 2 或 3 ,需要满足以下条件: 每个点都需要被赋值 权值为 1 的点共 n1 个 权值为 ...

最新文章

  1. 如何关闭win10自动更新_如何关闭win10系统自动更新
  2. Apache James使用的方法及相关心得(转)
  3. 2021考研计算机网络,2021考研:计算机网络复习重点
  4. K8S的HelloWorld之旅
  5. Hibernate 连接不同数据库的方言
  6. Java Timer、TimerTask
  7. tcp假连接_TCP 的那些事儿(上)
  8. void main(){char str[] = “\tab\n\014\\\“;printf(“%d“,strlen(str))}
  9. UVA 12299 - RMQ with Shifts 线段树
  10. C++ string 的学习摘录
  11. 技术考官如何面试应聘者的非技术素质
  12. vi中跳到首行或尾行
  13. 安卓最新版本_小米穿戴app下载安装-小米穿戴app官方版下载v1.2.1 安卓最新版本...
  14. json面试题_JAVA SSM 框架面试题,附答案!
  15. 红包系统流量高并发技术详解
  16. 夏斌:半年宏观调控思路的建议
  17. ocp认证考试报名_OCP最新报名考证流程
  18. Node+Vue实现高校公寓管理系统设计与开发
  19. JS:函数中的arguments
  20. 为什么你要拒绝我(苹果AppStore被拒理由大全)

热门文章

  1. iptables -j MARK --set-xmark 解析
  2. SiamFC:Fully-Convolutional Siamese Networks for Object Tracking
  3. cruisecontrol 配置
  4. 移动端框架 - Bootstrap
  5. 人人都会用的矢量设计软件,这6个不可不知道!
  6. gl-opendrive插件(车俩3D仿真模拟自动驾驶)
  7. mockjs的安装使用
  8. 查看分辨率的linux命令,Ubuntu: Linux下查看本机显示器分辨率(xrandr)
  9. 一般企业里的服务器采用的是什么系统?windows?还是linux?
  10. “富不过三代”怎么表达?