CF377A Maze题解
CF377A Maze
#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
#include <cstdio>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define _for(n,m,i) for (register int i = (n); i < (m); ++i)
#define _rep(n,m,i) for (register int i = (n); i <= (m); ++i)
#define lson rt<<1, l, mid
#define rson rt<<1|1, mid+1, r
#define PI acos(-1)
#define eps 1e-9
#define rint register int
#define F(x) ((x)/3+((x)%3==1?0:tb))
#define G(x) ((x)<tb?(x)*3+1:((x)-tb)*3+2)
using namespace std;
typedef long long LL;
typedef pair<LL, int> pli;
typedef pair<int, int> pii;
typedef pair<double, int> pdi;
typedef pair<LL, LL> pll;
typedef pair<double, double> pdd;
typedef map<int, int> mii;
typedef map<char, int> mci;
typedef map<string, int> msi;
template<class T>
void read(T &res) {int f = 1; res = 0;char c = getchar();while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar(); }while(c >= '0' && c <= '9') { res = res * 10 + c - '0'; c = getchar(); }res *= f;
}
const int ne[8][2] = {1, 0, -1, 0, 0, 1, 0, -1, -1, -1, -1, 1, 1, -1, 1, 1};
const int INF = 0x3f3f3f3f;
const int N = 510;
const LL Mod = 1e9+7;
const int M = 1e6+10;
char tu[N][N];
int n, m, k, ans, cnt;
void dfs(int x, int y) {//cout << x << " " << y << " " << cnt << " " << ans-k << endl;for(int i = 0, tx, ty; i < 4; ++i) {tx = x + ne[i][0], ty = y + ne[i][1];if(tx >=1 && ty >= 1 && tx <= n && ty <= m && tu[tx][ty] == 'X') {if(cnt == ans-k) return;tu[tx][ty] = '.'; ++cnt;dfs(tx, ty);}}
}
int main() {scanf("%d %d %d", &n, &m, &k);int fx, fy;_rep(1, n, i) {scanf("%s", tu[i]+1);_rep(1, m, j) if(tu[i][j] == '.') {tu[i][j] = 'X', ++ans;fx = i; fy = j;}}tu[fx][fy] = '.'; ++cnt; dfs(fx, fy);_rep(1, n, i) printf("%s\n", tu[i]+1);return 0;
}
CF377A Maze题解相关推荐
- nc15665 maze 题解 (传送门) 广搜bfs+优先队列
maze:原题链接 题目描述: 小明来到一个由n x m个格子组成的迷宫 ,有些格子是陷阱,用'#'表示,小明进入陷阱就会死亡,'.'表示没有陷阱.小明所在的位置用'S'表示,目的地用'T'表示. 小 ...
- [HDCTF2019]Maze 题解
少欲则心静,心静则事简. --人民日报 1.查壳 是一个加了upx壳的32位EXE文件 2.使用Kali Linux脱壳 ...
- 哈尔滨理工大学软件与微电子学院程序设计竞赛(同步赛) H
Maze 题解 DFS/BFS. 这里用的是 D F S DFS DFS.其中有并查集的思想. 题目所求为某个格子最多能到达的格子的数量,那么如果格子A可以到达格子B,则格子B必定能到格子A. 也就是 ...
- [JS][dfs]题解 | #迷宫问题#
题解 | #迷宫问题# 题目链接 迷宫问题 题目描述 定义一个二维数组 N*M ,如 5 × 5 数组下所示: int maze[5][5] = { 0, 1, 0, 0, 0, 0, 1, 1, 1 ...
- Codeforces Round #648 (Div. 2)题解 A-D
文章目录 A - Matrix Game B - Trouble Sort C - Rotation Matching D - Solve The Maze A - Matrix Game 题解:其实 ...
- LightOJ - 1027 A Dangerous Maze —— 期望
题目链接:https://vjudge.net/problem/LightOJ-1027 1027 - A Dangerous Maze PDF (English) Statistics Fo ...
- 【2019牛客暑期多校训练营(第二场)- E】MAZE(线段树优化dp,dp转矩阵乘法,线段树维护矩阵乘法)
题干: 链接:https://ac.nowcoder.com/acm/contest/882/E?&headNav=acm 来源:牛客网 Given a maze with N rows an ...
- TYUT-A专题题解(二)
TYUT-A专题题解(一) TYUT-A专题题解(二) 36暴力枚举 AOJ0008 Sum of 4 Integers[暴力]_海岛Blog-CSDN博客 HDU1407 测试你是否和LTC水平一样 ...
- AOAPC I: Beginning Algorithm Contests 题解
AOAPC I: Beginning Algorithm Contests 题解 AOAPC I: Beginning Algorithm Contests (Rujia Liu) - Virtual ...
最新文章
- Mysql技术内幕——InnoDB存储引擎
- 无需用户输入!Adobe提出自动生成高质量合成图像新方法
- 渗透测试中的文件传输技巧
- 02.centos6.4找不到ifcfg-eth0(静态ip配置)
- delete mysql 大表_无语了,直到今天,我才揪出MySQL磁盘消耗迅猛的“真凶”!
- 做个高颜值的优秀按钮,用 CSS3 实现社交按钮动画
- java.lang.IllegalStateException: getOutputStream() has already been called for this response
- 微软RPA工具Power Automate Desktop
- Django讲课笔记08:定义商城的数据模型
- 【Qt】arm-none-eabi-gdb-py.exe由于找不到python27.dll 无法继续执行代码
- OTSU 获取最佳阈值,及opencv二值化
- wifi服务器无响应如何修复,wifi打不开怎么修复?wifi打不开原因是什么
- 我从不劝退,我就是退。
- E+H电磁流量计你知道多少?
- python-matplotlib-柱状堆积图
- 计算机中解决不匹配,电脑显示屏显示不匹配.怎么办
- 人脸检测(十五)--改进版VJ人脸检测(LBP特征,VISAPP2017)
- 从文本文件读取数据方法
- 集成Health Kit时因证书问题出现错误码50063的解决方案
- Linux 强制破解root密码 是root密码哦
热门文章
- FLP不可能定理学习笔记
- python读取大智慧数据_用Python抓取大智慧除权数据
- Android提高第二十一篇之MediaPlayer播放网络视频
- 四种游泳姿势的动画图解,让你轻松学会游泳
- CVX下载、安装以及“此类型的变量不支持使用点进行索引错误”的错误
- 湖南元宇宙落地“快准狠”丨长沙马栏山产业园与LAYABOX合作打造元宇宙生态产业园...
- 搞IT要具备的特质,像沙僧一样~
- 研究型论文_基于流量异常分析多维优化的入侵检测方法
- hdu 3572 Task Schedule IPSA 最大流
- php 工商银行公众号支付代码_php实现工商银行在线支付接口