***做的时候判断当前位置为.的上下左右是否为*,如果全是改位置就改为*,如果四周中有为.,再DFS一下,其实就相当于把判断化为更小的子问题***

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<cctype>
#include<queue>
#include<vector>
#include<algorithm> using namespace std;
typedef long long LL;
#define N 101
#define INF 0x3f3f3f3f int n, m;
char maps[100][100];
int vis[100][100], w[N][N], b[N][N];
int dir[4][2]= {{1,0}, {0,1}, {-1,0}, {0,-1}}; int DFS(int x, int y)
{
b[x][y]=1;
for(int i=0; i<4; i++)
{
int nx, ny;
nx=x+dir[i][0];
ny=y+dir[i][1];
if(nx>=0&&nx<n&&ny>=0&&ny<m&&(maps[nx][ny]=='*'||b[nx][ny]))
w[x][y]++;
else if(nx>=0&&nx<n&&ny>=0&&ny<m&&(maps[nx][ny]=='.'&&!b[nx][ny]))
{
if(DFS(nx, ny))
w[x][y]++;
}
}
if(w[x][y]>=4)
return 1;
return 0;
} int main()
{
int T, cas=1;
scanf("%d", &T); while(T--)
{
scanf("%d%d", &n, &m);
for(int i=0; i<n; i++)
scanf("%s", maps[i]); memset(w, 0, sizeof(w));
memset(b, 0, sizeof(b)); printf("Case %d:\n", cas++);
for(int i=0; i<n; i++)
{
for(int j=0; j<m; j++)
{
if(maps[i][j]=='.')
{
memset(b, 0, sizeof(b));
memset(w, 0, sizeof(w));
DFS(i, j);
if(w[i][j]==4)
maps[i][j]='*';
}
printf("%c", maps[i][j]);
}
printf("\n");
}
}
return 0;
}

zzuli 1908的更多相关文章

  1. CentOS VirtualBox启动虚拟及报错:VirtualBox error: Kernel driver not installed (rc=1908)

    VirtualBox error: Kernel driver not installed (rc=1908) Hi all, Let me first say that this is my fin ...

  2. 解决Ubuntu下vbox的(rc=-1908)

    在Ubuntu下用虚拟机VBOX的时候总是遇到 Kernel driver not installed (rc=-1908) The VirtualBox Linux kernel driver (v ...

  3. hdu 1908 Double Queue

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1908 Double Queue Description The new founded Balkan ...

  4. Fedora安装VirtualBox时出现错误Kernel driver not installed (rc=-1908)的解决办法

    新建虚拟机后启动时出现如下错误: Kernel driver not installed (rc=-1908) The VirtualBox Linux kernel driver (vboxdrv) ...

  5. POJ 3481 &amp; HDU 1908 Double Queue (map运用)

    题目链接: PKU:http://poj.org/problem?id=3481 HDU:http://acm.hdu.edu.cn/showproblem.php?pid=1908 Descript ...

  6. VirtualBox,Kernel driver not installed (rc=-1908)

    http://hi.baidu.com/spt_form/item/316d6207b47b8ee03499020a VirtualBox,Kernel driver not installed (r ...

  7. zzuli oj 1134 字符串转换

    题目链接: https://acm.zzuli.edu.cn/zzuliacm/problem.php?id=1134 Description 输入一个以回车结束的字符串,它由数字和字母组成,请过滤掉 ...

  8. kali linux 安装virtualbox报错(rc=-1908)

    解决步骤: apt-get install dkms # 如何安装了dkms就跳过这步 apt-get install linux-headers-`uname -r` # 这个符号是TAB上方的符号 ...

  9. 线段树区间覆盖 蛤玮打扫教室(zzuli 1877)

    http://acm.zzuli.edu.cn/zzuliacm/problem.php?id=1877 Description   现在知道一共有n个机房,算上蛤玮一共有m个队员,教练做了m个签,每 ...

  10. (暴力+优化)学渣的逆袭 -- zzuli -- 1785

    http://acm.zzuli.edu.cn/problem.php?id=1785 学渣的逆袭 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 82  ...

随机推荐

  1. 《深入理解 FFmpeg》第一章彩色插图汇总

    layout: post title: "<深入理解 FFmpeg>第一章彩色插图" tags: - "FFmpeg" 这是<深入理解 FFm ...

  2. isAlive

    线程存活 当线程执行时显示线程存活 执行完毕为false

  3. 解决OpenCV编译时./bin: error while loading shared libraries: libopencv_highgui.so.3.2: cannot open的问题

    1.问题 安装好了opencv后,用其去检测是否可以使用时,出现了如下的问题: 2.解决 参考这篇博文点击 的配置环境即可解决

  4. 安卓之各组件的LayoutParams分析

    文章摘要 在Android开发中,LayoutParams是一个非常重要的概念,它用于描述View在其父容器中的布局行为.不同的ViewGroup有不同的LayoutParams子类,例如Linear ...

  5. 深入 K8s 网络原理(二)- Service iptables 模式分析

    目录 1. 概述 2. 准备 Service 和 Pods 资源 3. K8s 里 Service 的实现原理 3.1 kube-proxy 组件 3.2 iptables 简介 3.3 iptabl ...

  6. DRF限流

    https://www.django-rest-framework.org/api-guide/throttling/ 限制.控制客户端可以向 API 发出的请求的速率. 设置限流策略 默认限制策略可 ...

  7. 【C#】【命名空间(namespace)】.NET6.0后支持的顶级语句使用问题

    创建C#项目且使用.Net6.0以上的版本时,默认code会使用顶级语句形式: 1.略去static void Main(String[ ] args)主方法入口: 2.隐式使用(即隐藏且根据代码所需 ...

  8. ASR项目实战-产品分析

    分析Google.讯飞.百度.阿里.QQ.搜狗等大厂的ASR服务,可以罗列出一款ASR服务所需要具备的能力. 产品分类 ASR云服务产品,从用户体验.时效性.音频时长,可以划分为如下几类: 实时短音频 ...

  9. 神经网络优化篇:详解梯度检验(Gradient checking)

    梯度检验 梯度检验帮节省了很多时间,也多次帮发现backprop实施过程中的bug,接下来,看看如何利用它来调试或检验backprop的实施是否正确. 假设的网络中含有下列参数,\(W^{[1]}\) ...

  10. JavaFx设置图标(二)

    JavaFx设置图标(二) JavaFX 从入门入门到入土系列 JavaFx设置图标,需要注意,我这里是Maven管理项目 需要将图片放到resources/img/avatar.jpg下 impor ...