***做的时候判断当前位置为.的上下左右是否为*,如果全是改位置就改为*,如果四周中有为.,再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. Linux常用命令(持续完善中......)

    1.查看内存 top 2.查看磁盘存储情况 df -h 3.查看端口占用情况 netstat -tunlp | grep 端口号 4.查看报告系统运行时长及平均负载 uptime 5.查看进程 ps ...

  2. LeetCode5716:好因子的最大数目(数学、快速幂)

    解题思路:因为primeFactors比较大,所以需要使用快速幂. class Solution: def quick_pow(self,base,x): ans = 1 while x>0: ...

  3. ElasticSearch索引库的增删改查

    官方文档:https://www.elastic.co/guide/en/elasticsearch/reference/6.8/indices.html 创建索引.设置分片 https://www. ...

  4. MES系统怎么实现车间管理中的生产计划和排产计划

    生产计划和排产计划都是制造企业中非常重要的概念,它们的目的是为了确保企业能够按时交付高质量的产品,同时还要保持生产效率和成本效益. 一.生产计划 生产计划是指制造企业为了满足客户需求而制定的计划,它包 ...

  5. springboot整合mybatis步骤思路

    /** * springboot整合mybatis步骤思路 * 依赖导入 * 建表 * 实体类 * mapper配置文件 * mapper接口 * yaml配置 * properties配置数据库连接 ...

  6. 【云原生 | Kubernetes 系列】—K8S部署RocketMQ集群(双主双从+同步模式)

    [云原生 | Kubernetes 系列]-K8S部署RocketMQ集群(双主双从+同步模式) 版权 本文为云录原创文章,转载无需和我联系,但请注明来自云录 https://www.yunzhuan ...

  7. DDD落地实践-架构师眼中的餐厅 | 京东云技术团队

    本文以餐厅场景为叙事主线,以领域驱动为核心思想,结合架构设计与功能设计方法论.是从领域分析到落地的全过程案例,内容偏重于落地,因此不乏一些探讨,欢迎指正. 文章较长.全程干货.耐心读完.必有收获. 本 ...

  8. Python——第二章:字典的循环、嵌套、"解构"(解包)

    字典进阶操作 -- 循环和嵌套 字典的循环 我们先看直接打印字典的样子,会分别对每对key:value进行打印,并使用,分隔他们 dic = { "赵四": "特别能歪嘴 ...

  9. DNSlog注入(利用DNSlog平台将SQL盲注变成回显注入)

    前言 什么是UNC 什么是DNSlog注入 DNSlog注入的条件 防止DNSlog注入的几个措施 sqli-labs试验 前言 前几天面试的时候,面试官问我知不知道OOB(带外数据). 当时我蒙了, ...

  10. JavaFx之使用指定字体样式(二十九)

    JavaFx之使用指定字体样式(二十九) javafx use specified font 29 javafx默认的字体样式太丑,可能需要我们自定义字体样式. 之前说好放弃学习javafx,没想到越 ...