Codeforces Round #297 (Div. 2) 525D Arthur and Walls(dfs)
来源:互联网 发布:淘宝线下代购 编辑:程序博客网 时间:2024/06/05 03:08
题目链接:点击打开链接
给出n * m的地图, '*'代表墙, '.'代表房间, 墙可以变为房间, 现要求房间为长方形, 问最少需要变化后的房间.
dfs的条件是四个点组成的形状只有一个'*', 于是将这个墙变为房间, 继续dfs, 可以使得变化最少.
AC代码:
#include "iostream"#include "cstdio"#include "cstring"#include "algorithm"#include "queue"#include "stack"#include "cmath"#include "utility"#include "map"#include "set"#include "vector"#include "list"#include "string"#include "cstdlib"using namespace std;typedef long long ll;const int MOD = 1e9 + 7;const int INF = 0x3f3f3f3f;const int MAXN = 2005;int n, m;char maze[MAXN][MAXN];void Dfs(int x, int y){if(x >= n - 1 || y >= m - 1 || x < 0 || y < 0) return;int xx, yy, s = 0;for(int i = 0; i < 2; ++i)for(int j = 0; j < 2; ++j)if(maze[x + i][y + j] == '*') {s++;xx = x + i;yy = y + j;}if(s == 1) {maze[xx][yy] = '.';for(int i = -1; i < 1; ++i)for(int j = -1; j < 1; ++j)Dfs(xx + i, yy + j);}}int main(int argc, char const *argv[]){scanf("%d %d", &n, &m);for(int i = 0; i < n; ++i)scanf("%s", maze[i]);for(int i = 0; i < n - 1; ++i)for(int j = 0; j < m - 1; ++j)Dfs(i, j);for(int i = 0; i < n; ++i)printf("%s\n", maze[i]);return 0;}
1 0
- Codeforces Round #297 (Div. 2) 525D Arthur and Walls(dfs)
- Codeforces Round #297 (Div. 2) D. Arthur and Walls
- Codeforces Round #297 (Div. 2) D - Arthur and Walls
- Codeforces Round #297 (Div. 2) D Arthur and Walls
- Codeforces 525D Arthur and Walls 【DFS】
- Codeforces 525D Arthur and Walls 【DFS】
- Codeforces Round #297 (Div. 2) -- D. Arthur and Walls (判断矩形)
- Codeforces Round #297 (Div. 2) D Arthur and Walls(bfs)
- Codeforces Round #297 (Div. 2) D题. Arthur and Walls(BFS)
- D. Arthur and Walls(Codeforces Round #297 (Div. 2) 搜索(BFS))
- Codeforces Round #297 (Div. 2) D - Arthur and Walls (深搜)
- Codeforces Round #297 (Div. 2) D - Arthur and Walls [思维]【思维】
- Codeforces Round #297 (Div. 2)D. Arthur and Walls 搜索bfs
- #297 (div.2) D. Arthur and Walls
- Codeforces--525D--Arthur and Walls(DFS)
- Codeforces 525D Arthur and Walls 【Dfs+思维】
- DFS(思维) CodeForces - 525D Arthur and Walls
- Codeforces #297( div2) D. Arthur and Walls ( DFS
- 5.数据挖掘概念笔记——数据立方体技术
- Java学习笔记(1):1.概述之计算机语言概述
- 修改lenet网络进行训练(一)
- 6.数据挖掘概念笔记——挖掘频繁模式、关联和相关性术
- c#面试题
- Codeforces Round #297 (Div. 2) 525D Arthur and Walls(dfs)
- RippleDrawable 的简单使用
- LeetCode 258. Add Digits
- Servlet之过滤器
- 从数据库丢失更新想到的一些问题
- 6S大气传输模型修改源码添加、自定义卫星光谱响应(以HJ-1B CCD为例)
- CMake与Make
- 欢迎使用CSDN-markdown编辑器
- 从github上clone项目