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 ...
随机推荐
- MybatisPlus条件查询方法全解
1.是什么? MybatisPlus通过条件构造器可以组装复杂的查询条件,写一些复杂的SQL语句,从而简化我们的开发提升我们的开发效率 # 可以简单的理解为就是我们写SQL语句时where后面的条件 ...
- HDU-2586 How far away?
There are n houses in the village and some bidirectional roads connecting them. Every day peole alwa ...
- 37. 干货系列从零用Rust编写负载均衡及代理,负载均衡中try_files实现
wmproxy wmproxy已用Rust实现http/https代理, socks5代理, 反向代理, 静态文件服务器,四层TCP/UDP转发,七层负载均衡,内网穿透,后续将实现websocket代 ...
- ElasticSearch之cat pending tasks API
命令样例如下: curl -X GET "https://localhost:9200/_cat/pending_tasks?v=true&pretty" --cacert ...
- 良心国产工具,比Xshell好用还免费!
使用或维护Linux系统的都知道,我们日常对服务器的操作,一般都会借助SSH工具远程登录到服务器之后进行操作.常用的SSH工具有不少,比如:Xshell.Putty.SSH Secure Shell ...
- Spring源码学习笔记6——Spring bean的实例化
一丶前言 前面我们了解到读取xml or 根据扫描路径生成BeanDefinition并注册到BeanFactory,相当于我们具备了生火做饭的原材料:BeanDefinition,接下来就是Spri ...
- [Python急救站]学生管理系统链接数据库
相信很多人在初学Python的时候,经常最后作业就是完成一个学生管理系统,但是我们来做一个完美的学生管理系统,并且将数据储存到数据库里. 我们先看看我们的数据库怎么设置. 首先呢,我选择用的是SQL ...
- 数据库开发实战教程:使用Python连接Kerberos的Presto
[摘要]本文将为大家带来Python连接presto开源的两个实践案例. Python连接presto开源提供了以下两个库可以使用 presto-python-client:https://githu ...
- 低代码开发不靠谱?看低代码开发在物联网APP开发中的应用
摘要:云编排式物联APP开发平台可通过云端可视化编排开发,边端远程自动化部署,云边协同管理运维的方式,实现物联网APP快速开发,海量边端应用管理. 0 引言 当前,物联网技术正在推动人类社会从&quo ...
- 在openGauss上做开发?这个大赛拿出30万寻找开源的你
摘要:信创"大比武"鲲鹏基础软件开发赛道,面向openGauss设置2个赛题,将推进openGauss人才建设,加快openGauss"产学研用"人才培养. 多 ...