***做的时候判断当前位置为.的上下左右是否为*,如果全是改位置就改为*,如果四周中有为.,再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. 吉特日化MES & 标签的设计与选择

    吉特日化MES & 标签的设计与选择:如今条码和二维码在生活中随处可见,作为一种能够快速精准读取识别的手段,条码和二维码在生产车间也应用的较为广泛.如果说条码和二维码哪一种更好,我更加倾向于使 ...

  2. [ARC169E] Avoid Boring Matches

    题解链接 非常厉害的一道题. 考虑无解是什么情况? R 的个数超过 \(2^{n-1}\) 先考虑如何判定.从前往后考虑,如果遇到一个 B,那么如果后面有 R,就选最靠前的 R,否则选最靠后的一个 B ...

  3. [CF1264D]Beautiful Bracket Sequence

    题目描述 This is the hard version of this problem. The only difference is the limit of $ n $ - the lengt ...

  4. Vue3节流指令封装

    节流指令 import { ObjectDirective } from 'vue' interface ThrottleEl extends HTMLElement { throttleEvent: ...

  5. 报错信息如下:出现身份验证错误。要求的函数不受支持。可能是由于CredSSP加密数据库修正。

    微软官方已出补丁包:CVE-2018-0886 的 CredSSP 更新 Windows Server 2016, all editions.Windows Server 2012 R2 Standa ...

  6. Python中numpy出现has no attribute '_no_nep50_warning'错误的一个解决方案

      本文介绍在Python中,numpy库出现报错module 'numpy' has no attribute '_no_nep50_warning'的解决方法.   一次,在运行一个Python代 ...

  7. 深入理解JavaScript堆栈、事件循环、执行上下文和作用域以及闭包

    1. 堆栈 在JavaScript中,内存堆是内存分配的地方,调用栈是代码执行的地方. 原始类型的保存方式:在变量中保存的是值本身,所以原始类型也被称之为值类型. 对象类型的保存方式:在变量中保存的是 ...

  8. String 类和 STL (Standard Template Library)

    目录 一. string 类 1. 构造字符串 2. string类输入 3. 使用字符串 4. 其他string类方法 5. 字符串种类 一. string 类 很多应用程序都需要处理字符串.C语言 ...

  9. CSS 基础 2 - Box Model 盒模型

    CSS 基础 2 - Box Model 盒模型 Box Model 盒模型是网页布局的前提.网页布局的几种方式: Table(过时):在 CSS 出现之前,一般用表格布局(将表格边框线隐藏) Flo ...

  10. DataX快速入门

    DataX3.0快速入门 一.DataX3.0概览 DataX是阿里云DataWorks数据集成的开源版本,在阿里巴巴集团内部被广泛使用的离线数据同步工具/平台.解决了数据库之中的数据同步.迁移问题, ...