zzuli 1908
***做的时候判断当前位置为.的上下左右是否为*,如果全是改位置就改为*,如果四周中有为.,再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的更多相关文章
- 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 ...
- 解决Ubuntu下vbox的(rc=-1908)
在Ubuntu下用虚拟机VBOX的时候总是遇到 Kernel driver not installed (rc=-1908) The VirtualBox Linux kernel driver (v ...
- hdu 1908 Double Queue
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1908 Double Queue Description The new founded Balkan ...
- Fedora安装VirtualBox时出现错误Kernel driver not installed (rc=-1908)的解决办法
新建虚拟机后启动时出现如下错误: Kernel driver not installed (rc=-1908) The VirtualBox Linux kernel driver (vboxdrv) ...
- POJ 3481 & HDU 1908 Double Queue (map运用)
题目链接: PKU:http://poj.org/problem?id=3481 HDU:http://acm.hdu.edu.cn/showproblem.php?pid=1908 Descript ...
- VirtualBox,Kernel driver not installed (rc=-1908)
http://hi.baidu.com/spt_form/item/316d6207b47b8ee03499020a VirtualBox,Kernel driver not installed (r ...
- zzuli oj 1134 字符串转换
题目链接: https://acm.zzuli.edu.cn/zzuliacm/problem.php?id=1134 Description 输入一个以回车结束的字符串,它由数字和字母组成,请过滤掉 ...
- kali linux 安装virtualbox报错(rc=-1908)
解决步骤: apt-get install dkms # 如何安装了dkms就跳过这步 apt-get install linux-headers-`uname -r` # 这个符号是TAB上方的符号 ...
- 线段树区间覆盖 蛤玮打扫教室(zzuli 1877)
http://acm.zzuli.edu.cn/zzuliacm/problem.php?id=1877 Description 现在知道一共有n个机房,算上蛤玮一共有m个队员,教练做了m个签,每 ...
- (暴力+优化)学渣的逆袭 -- zzuli -- 1785
http://acm.zzuli.edu.cn/problem.php?id=1785 学渣的逆袭 Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 82 ...
随机推荐
- Oracle数据字典(各种视图、表)
数据字典是存放整个数据库实例重要信息的一组表,这些数据字典大部分都是SYS用户所有. 数据字典的构成 Oracle数据字典名称由前缀和后缀组成,使用下画线"_"连接.其代表的含义如 ...
- Kernel Memory 入门系列:生成并获取文档摘要
Kernel Memory 入门系列:生成并获取文档摘要 前面在RAG和文档预处理的流程中,我们得到一个解决方案,可以让用户直接获取最终的问题答案. 但是实际的业务场景中,仍然存在一些基础的场景,不需 ...
- 数字孪生技术与VR技术的结合会为我们带来什么?
数字孪生技术与虚拟现实(VR)技术的结合为我们打开了全新的可能性和机遇.这个强大的联合为各个领域带来了巨大的影响和创新. 首先,数字孪生技术与VR技术的结合可以为设计和规划过程提供更直观.身临其境的体 ...
- 获取微信的token工具类
import cn.hutool.extra.spring.SpringUtil; import cn.hutool.http.HttpUtil; import cn.RedisUtil; impor ...
- 性能集成监控系统exporter+Prometheus+Grafana
Prometheus 是一个时序数据库,存数据 exporter是收集器,来收集被监控的数据,想要监控不同的内容,就使用不同的exporter,这个exporter应该放在被测服务器上,再把expor ...
- Ubuntu系统部署后优化
Ubuntu系统配置调整 前期准备 #更改主机名,重启后不变 hostnamectl set-hostname Zabbix-Server01 #更改主机名,重启后变回从前 hostname Zabb ...
- 马某 说c# 不开源,他是蠢还是坏?
马某在视频 计算机主流开发语言的现状和未来3-5年的发展前景--Java.Golang.Python.C\C#\C++.JS.前端.AI.大数据.测试.运维.网络安全 点评各种语言,其中说到C# 的时 ...
- 别再傻傻地用 ifconfig 查地址了!这条命令足以让你摘掉小白工程师的帽子
大家好,我是民工哥. 众所周知,在 Linux 系统中,ip 和 ifconfig 这个两命令的功能十分相似,ifconfig 是 net-tools 中已被弃用的一个命令,很多年前就已经没有维护了. ...
- C语言基础之因子分解
要求: 从键盘输入一个正整数,然后将该整数分解为1和各个质因子的相乘,如果输入的整数本身就是质数,则应分解为1和该数本身相乘. 输出格式: 因子分解,因子由小到大输出. 如:1* 2* 2* 3 代码 ...
- 新版的Django中的path不能使用正则表达式
新版的path 虽然 取代了 之前的url,但是在写路由的时候不能在路由中直接写正则表达式,不然会找不到页面. 解决方法使用 re_path from django.urls import re_pa ...