BFS E题
来源:互联网 发布:苹果mac系统更新macos 编辑:程序博客网 时间:2024/06/15 19:11
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
char mp[512][512];
bool vis[512][512];
int n,m,k;
void dfs(int x,int y)
{
if(x<0||x>=n||y<0||y>=m)
return ;
if(mp[x][y]!='.')
return ;
if(vis[x][y])
return ;
vis[x][y]=true;
dfs(x+1,y);
dfs(x-1,y);
dfs(x,y+1);
dfs(x,y-1);
if(k)
{
mp[x][y]='X';
k--;
}
}
int main()
{
scanf("%d%d%d",&n,&m,&k);
for(int i=0; i<n; i++)
scanf("%s",mp[i]);
for(int i=0; i<n&&k; i++)
for(int j=0; j<m&&k; j++)
dfs(i,j);
for(int i=0; i<n; i++)
puts(mp[i]);
return 0;
}
#include <cstdio>
#include <cstring>
using namespace std;
char mp[512][512];
bool vis[512][512];
int n,m,k;
void dfs(int x,int y)
{
if(x<0||x>=n||y<0||y>=m)
return ;
if(mp[x][y]!='.')
return ;
if(vis[x][y])
return ;
vis[x][y]=true;
dfs(x+1,y);
dfs(x-1,y);
dfs(x,y+1);
dfs(x,y-1);
if(k)
{
mp[x][y]='X';
k--;
}
}
int main()
{
scanf("%d%d%d",&n,&m,&k);
for(int i=0; i<n; i++)
scanf("%s",mp[i]);
for(int i=0; i<n&&k; i++)
for(int j=0; j<m&&k; j++)
dfs(i,j);
for(int i=0; i<n; i++)
puts(mp[i]);
return 0;
}
阅读全文
0 0
- BFS E题
- ECPC16-E. Jumping(bfs)
- CF 789E BFS
- BFS 之 E
- Codeforces 190E Counter Attack【思维+Bfs】好题!
- BFS-E - Find a way
- Codeforces 653E (BFS set)
- codeforces-gym-100187-E【bfs】
- Codeforces E. Two Labyrinths ( BFS
- SDNU-BFS——E
- Codeforces Round #397 E. Tree Fold(bfs,想法题,好题)
- HLG校赛个人赛 E题 ( 并查集+二维BIT+deque+BFS )
- 2016 ACM-ICPC 亚洲区域赛北京站E题 What a Ridiculous Election (BFS预处理)
- codeforces 152E bfs+状态压缩
- codeforces 591 E (bfs and bf)
- Codeforces 276E Little Girl and Problem on Trees【线段树+Bfs序+Dfs序】好题!
- bfs题
- E - Children of the Candy Corn -DFS模拟+bfs
- 《春风十里不如你》身体骚动的魔性,精神成长的传记
- go get code.google.com/p/go.net/websocket失败
- 一种简单交换排序
- 使用 NLTK 对文本进行清洗,索引工具
- 面向对象的概念 | 类与对象 | java基础
- BFS E题
- 7种深度学习工具介绍
- MySQL命令行操作
- Python3学习(7)--函数【Function】
- codevs 1022 覆盖
- css禅院
- 开源项目
- Isomorphic Strings
- PHP 处理最普通的 XML 任务