Codeforces 378C
来源:互联网 发布:服务器数据迁移流程图 编辑:程序博客网 时间:2024/06/04 23:23
DFS连通块,思路就是搜到底,然后一个一个回溯(填上X)上来
#include <iostream>#include <stdio.h>#include <string.h>#include <stack>#include <queue>#include <map>#include <set>#include <vector>#include <math.h>#include <algorithm>using namespace std;#define LL long longconst double pi = acos(-1.0);#define Len 200005#define mod 19999997const int INF = 0x3f3f3f3f;#define exp 1e-6#define N 520bool vis[N][N];char ma[N][N];int n,m,k;void DFS(int x,int y){ if(x<0||y<0||x>=n||y>=m||vis[x][y]||ma[x][y]=='#') return; vis[x][y]=1; //一直搜到底啊 DFS(x-1,y); DFS(x+1,y); DFS(x,y-1); DFS(x,y+1); if(!k) return; ma[x][y]='X'; --k;}int main(){ cin>>n>>m>>k; for(int i=0;i<n;i++) scanf("%s",ma[i]); int flag=0; memset(vis,0,sizeof(vis)); for(int i=0;i<n;i++) { for(int j=0;j<m;j++) { if(ma[i][j]=='.') { DFS(i,j); flag=1; break; } } if(flag) break; } for(int i=0;i<n;i++) printf("%s\n",ma[i]);}
0 0
- Codeforces 378C
- codeforces 378C MAZE
- Codeforces-340-C(c++)
- Codeforces-507-C(c++)
- CodeForces 731C C
- CodeForces-612C C
- codeforces #378C(733.C) Epidemic in Monstropolis
- Codeforces Round #378 (Div. 2) C && Codeforces 733C (模拟)详解(两种写法)
- CODEFORCES 265C CODEFORCES, 265C
- codeforces #78 div2 C
- Codeforces 117C Cycle
- CodeForces 209C
- CodeForces 156C Cipher
- codeforces 148 div2 C
- codeforces 242C
- Codeforces-234C Weather
- codeforces 106C Buns
- codeforces 158C
- Java compiler level does not match解决方法
- UVa 12592 - Slogan Learning of Princess
- Oracle ORA-01033: ORACLE initialization or shutdown in progress 错误解决办法
- Android,图形图像之使用Path类
- Redis学习笔记(7)-info命令详解
- Codeforces 378C
- adt或者eclipse打开文件所在位置的插件
- [Unity3D] MoveTowards、Lerp、Slerp
- P=NP?
- 通过ftp上传图片 工具类
- Java内存区域理解
- 解决 导入他人做的项目后出现Multiple annotations found at this line 的问题
- Android画图Path的使用
- win10无法通过IPC连接远程电脑