Codeforces 377 A Maze【DFS】
题意:给出n*m的矩阵,矩阵由'.'和'#'组成,再给出k,表示需要在'.'处加k堵墙,使得剩下的'.'仍然是连通的
先统计出这个矩阵里面总的点数'.'为sum
因为题目说了一定会有一个解,所以找到一个'.',就开始搜,搜到sum-k个连通的点的时候跳出,剩下的没有访问过的点就全部填成墙
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cmath>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<algorithm>
using namespace std; typedef long long LL;
const int INF = (<<)-;
const int mod=;
const int maxn=; char g[maxn][maxn];
int vis[maxn][maxn];
int ans,n,m,k,cnt;
int dir[][]={,,-,,,,,-}; void dfs(int x,int y){
vis[x][y]=;
cnt++;
if(cnt==ans) return;
for(int i=;i<;i++){
if(cnt==ans) return;
int xx=x+dir[i][];
int yy=y+dir[i][];
if(xx<||xx>n||yy<||yy>m||vis[xx][yy]||g[xx][yy]!='.') continue;
dfs(xx,yy);
}
} int main(){
scanf("%d %d %d",&n,&m,&k);
for(int i=;i<=n;i++)
for(int j=;j<=m;j++) cin>>g[i][j]; ans=;
for(int i=;i<=n;i++){
for(int j=;j<=m;j++){
if(g[i][j]=='.') ans++;
}
}
ans=ans-k; for(int i=;i<=n;i++){
int flag=;
for(int j=;j<=m;j++){
cnt=;
if(g[i][j]=='.'){
dfs(i,j);
flag=;
break;
}
}
if(flag) break;
} for(int i=;i<=n;i++){
for(int j=;j<=m;j++){
if(g[i][j]=='.'&&!vis[i][j]) g[i][j]='X';
}
} for(int i=;i<=n;i++){
for(int j=;j<=m;j++)
printf("%c",g[i][j]);
printf("\n");
}
return ;
}
Codeforces 377 A Maze【DFS】的更多相关文章
- Codeforces 667C Reberland Linguistics【DFS】
一道卡题意的题. 题目链接: http://codeforces.com/problemset/problem/667/C 题意: 一个串可以看成一个长度大于4的根,加上其后面的若干个相邻(in a ...
- Codeforces 659E New Reform【DFS】
题目链接: http://codeforces.com/problemset/problem/659/E 题意: 给定n个点和m条双向边,将双向边改为单向边,问无法到达的顶点最少有多少个? 分析: 无 ...
- Codeforces 1036C Classy Numbers 【DFS】
<题目链接> 题目大意: 对于那些各个位数上的非0数小于等于3的数,我们称为 classy number ,现在给你一个闭区间 [L,R] (1≤L≤R≤1018).,问你这个区间内有多 ...
- 【第40套模拟题】【noip2011_mayan】解题报告【map】【数论】【dfs】
目录:1.潜伏者 [map] 2.Hankson的趣味题[数论]3.mayan游戏[dfs] 题目: 1. 潜伏者(spy.pas/c/cpp)[问题描述]R 国和S 国正陷入战火之中,双方都互派间谍 ...
- Kattis - glitchbot 【DFS】
Kattis - glitchbot [DFS] 题意 有一个机器人 刚开始在(0, 0),然后给出一个目标点,并且会给出一系列指令,但是其中会有一个指令是错误的.我们需要找出那个指令,并且改成正确的 ...
- HDU 6113 度度熊的01世界 【DFS】(2017"百度之星"程序设计大赛 - 初赛(A))
度度熊的01世界 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- [CodeForces - 1225D]Power Products 【数论】 【分解质因数】
[CodeForces - 1225D]Power Products [数论] [分解质因数] 标签:题解 codeforces题解 数论 题目描述 Time limit 2000 ms Memory ...
- 【dfs】codeforces Journey
http://codeforces.com/contest/839/problem/C [AC] #include<iostream> #include<cstdio> #in ...
- 【DFS】codeforces B. Sagheer, the Hausmeister
http://codeforces.com/contest/812/problem/B [题意] 有一个n*m的棋盘,每个小格子有0或1两种状态,现在要把所有的1都变成0,问最少的步数是多少?初始位置 ...
随机推荐
- Ckeditor 中一些核心的对象的作用
1.CKEditor CKEditor对象用于掌管全局,他是一个单例对象,管理着所有实例化了的编辑框. 通过replace方法创建编辑框实例. 2.CKEditor.editor 表示一个编辑框实例, ...
- PHP扩展迁移为兼容PHP7记录
PHP7扩展编写的时候,提供的一些内核方法和之前的PHP之前的版本并不能完全兼容.有不少方法参数做了调整.下面是在迁移过程中遇到的一些问题.记录下来,避免大家再踩坑. PHP7扩展开发之hello w ...
- Javascript 正则表达式笔记2
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...
- C# 和Jsonp的一个小demo 用jQuery与JSONP轻松解决跨域访问的问题
客服端: 在A项目下面 建立一个 JsonpClient.aspx页面,代码如下: <%@ Page Language="C#" AutoEventWireup=& ...
- Peer certificate cannot be authenticated with known CA certificates.
I was trying to post to a webservice and was getting the 60 error code: Peer certificate cannot be a ...
- 【hdu3247-Resource Archiver】位压DP+AC自动机+SPFA
题意:给定n个文本串,m个病毒串,文本串重叠部分可以合并,但合并后不能含有病毒串,问所有文本串合并后最短多长. (2 <= n <= 10, 1 <= m <= 1000) 题 ...
- 解决安装rpm时lib冲突:libstdc++-2-libc6.1-1-2.9.0.so from install of compat-libstdc++-7.3-2.96.118 conflicts with file from ...
sudo rpm -ivh xxx.rpm -aid --force [oracle@localhost Oracle]$ .i386.rpm compat-libstdc++-devel-.i386 ...
- hdu 1847 Good Luck in CET-4 Everybody!(简单博弈SG)
#include<stdio.h> #include<string.h> #define N 1010 int hash[N]; int sg[N]; void GetSG() ...
- Spring学习总结(2)——Spring IOC的前世今生
前些天,参与了公司内部小组的一次技术交流,主要是针对<IOC与AOP>,本着学而时习之的态度及积极分享的精神,我就结合一个小故事来初浅地剖析一下我眼中的“IOC前世今生”,以方便初学者能更 ...
- SMB2 Protocol – 简介(应用层协议主要用于在计算机间共享文件、打印机、串口等)
SMB2 Protocol – 简介 SMB协议简介: 服务器信息块(SMB)协议是一个应用层协议主要用于在计算机间共享文件.打印机.串口等. 在介绍SMB协议的时候,一般提到使用的端口为139,44 ...