题目链接:http://agc014.contest.atcoder.jp/tasks/agc014_c

题意:略。

题解:第一遍bfs找到所有可以走的点并标记步数,看一下最少几步到达所有没锁的点,然后再

for一遍所有标记过的点之后就是考虑向上走向左走向右走向下走(直走)。

#include <iostream>
#include <cstring>
#include <cstdio>
#include <queue>
using namespace std;
const int M = 1e3;
char mmp[M][M] , s[M][M];
int h , w , k , step[M][M] , dr[4][2] = {1 , 0 , -1 , 0 , 0 , 1 , 0 , -1};
struct TnT {
int x , y , step , flag;
};
bool vis[M][M];
void bfs(TnT sta) {
memset(step , 0 , sizeof(step));
step[sta.x][sta.y] = 1;
memset(vis , false , sizeof(vis));
vis[sta.x][sta.y] = true;
queue<TnT>q;
q.push(sta);
while(!q.empty()) {
TnT gg = q.front();
q.pop();
for(int i = 0 ; i < 4 ; i++) {
TnT gl = gg;
gl.x += dr[i][0];
gl.y += dr[i][1];
if(gl.x >= 0 && gl.x < h && gl.y >= 0 && gl.y < w && mmp[gl.x][gl.y] != '#' && !vis[gl.x][gl.y]) {
gl.step++;
step[gl.x][gl.y] = gl.step;
vis[gl.x][gl.y] = true;
q.push(gl);
}
}
}
}
int main() {
scanf("%d%d%d" , &h , &w , &k);
for(int i = 0 ; i < h ; i++) {
scanf("%s" , mmp[i]);
}
TnT sta;
for(int i = 0 ; i < h ; i++) {
for(int j = 0 ; j < w ; j++) {
if(mmp[i][j] == 'S') {
sta.x = i , sta.y = j;
break;
}
}
}
sta.step = 0 , sta.flag = k;
bfs(sta);
int ans = 1000000000;
for(int i = 0 ; i < h ; i++) {
for(int j = 0 ; j < w ; j++) {
if(step[i][j] != 0) {
if(i == 0 || i == h - 1 || j == 0 || j == w - 1) {
int gg = step[i][j];
if(gg % k == 0) {
ans = min(ans , gg / k);
}
else {
ans = min(ans , gg / k + 1);
}
}
else {
int gg = step[i][j] , gl = 0;
if(gg % k == 0) {
gl = gg / k;
}
else {
gl = gg / k + 1;
}
gg = i;
if(gg % k == 0) {
ans = min(ans , gl + gg / k);
}
else {
ans = min(ans , gl + gg / k + 1);
}
gg = j;
if(gg % k == 0) {
ans = min(ans , gl + gg / k);
}
else {
ans = min(ans , gl + gg / k + 1);
}
gg = h - 1 - i;
if(gg % k == 0) {
ans = min(ans , gl + gg / k);
}
else {
ans = min(ans , gl + gg / k + 1);
}
gg = w - 1 - j;
if(gg % k == 0) {
ans = min(ans , gl + gg / k);
}
else {
ans = min(ans , gl + gg / k + 1);
}
}
}
}
}
printf("%d\n" , ans);
return 0;
}

Atcoder C - Closed Rooms(思维+bfs)的更多相关文章

  1. Atcoder Grand Contest 039B(思维,BFS)

    #define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using namespace std;int col[207],s[207],n;c ...

  2. Codeforces Round #297 (Div. 2) D. Arthur and Walls [ 思维 + bfs ]

    传送门 D. Arthur and Walls time limit per test 2 seconds memory limit per test 512 megabytes input stan ...

  3. Vladik and Favorite Game CodeForces - 811D (思维+BFS+模拟+交互题)

    D. Vladik and Favorite Game time limit per test 2 seconds memory limit per test 256 megabytes input ...

  4. Valid BFS? CodeForces - 1037D(思维 bfs)

    我真是一只菜狗......emm... 题意: 判断一个从1开始的队列是否可以按照bfs的顺序 进行遍历..必须从1开始...然后后边依次是bfs顺序 解析: 看代码能看懂吧...emm...就是把每 ...

  5. 魔戒(思维+bfs)

    Description 蓝色空间号和万有引力号进入了四维水洼,发现了四维物体--魔戒. 这里我们把飞船和魔戒都抽象为四维空间中的一个点,分别标为 "S" 和 "E&quo ...

  6. atcoder E - Jigsaw(思维)

    题目链接:http://agc017.contest.atcoder.jp/tasks/agc017_e 题解:这题很巧妙运用了cnt[i]抽象的表示了上下互补的状态,最后上面突出的一定要处理完.下面 ...

  7. Atcoder C - +/- Rectangle(思维+构造)

    题目链接:http://agc016.contest.atcoder.jp/tasks/agc016_c 题解:挺简单的构造,很容易想到的构造方法就是(h*w)的小矩阵里其他值赋值为1,最后一个赋值为 ...

  8. Atcoder F - Mirrored(思维+搜索)

    题目链接:http://arc075.contest.atcoder.jp/tasks/arc075_d 题意:求rev(N)=N+D的个数,rev表示取反.例如rev(123)=321 题解:具体看 ...

  9. CF543B Destroying Roads 枚举 + 思维 + BFS

    Code: #include <bits/stdc++.h> #define ll long long #define setIO(s) freopen(s".in", ...

随机推荐

  1. 北大ACM试题分类+部分解题报告链接

    转载请注明出处:優YoU http://blog.csdn.net/lyy289065406/article/details/6642573 部分解题报告添加新内容,除了原有的"大致题意&q ...

  2. hdu 6406 Taotao Picks Apples (线段树)

    Problem Description There is an apple tree in front of Taotao's house. When autumn comes, n apples o ...

  3. abp(net core)+easyui+efcore实现仓储管理系统目录

    abp(net core)+easyui+efcore实现仓储管理系统目录 abp(net core)+easyui+efcore实现仓储管理系统——ABP总体介绍(一) abp(net core)+ ...

  4. 并发编程(3)——ThreadPoolExecutor

    ThreadPoolExecutor 1. ctl(control state) 线程池控制状态,包含两个概念字段:workerCount(线程有效数量)和runState(表示是否在运行.关闭等状态 ...

  5. android——SQLite数据库存储(创建)

    Android 专门提供了SQLiteOpenHelper帮助类,借助这个类就可以非常简单的对数据库进行创建和升级. 首先SQLiteOpenHelper是一个抽象类,在使用的时候需要创建一个自己的帮 ...

  6. DT-06 For AT

    乐鑫官方AT指令固件- 最新1.5.4版本 此固件仅支持AT指令对模块进行操作. 1.DT-06固件的烧录 1.1打开ESP模块下载工具ESPFlashDownloadTool,选择需要下载的固件,填 ...

  7. p2p 打洞专场(转)

    就像1000个人眼中有1000个哈姆雷特一样,每个人眼中的区块链也是不一样的!作为技术人员眼中的区块链就是将各种技术的融合,包括密码学,p2p网络,分布式共识机制以及博弈论等.我们今天就来讨论一下区块 ...

  8. 发布一个自己的jar包给全球人使用

    目录 项目准备 sonatype 注册 申请sonatype工单 gpg配置 项目配置 依赖oss-parent 自定义配置 pom配置 全局settings配置 发布 验证 maven 项目对于我们 ...

  9. Missing artifact XXXXX:jar:1.9.1 解决错误问题

    昨天导过来一个maven工程的一个项目,由于自己meven库中有许多现成的jar包,但是还是有一些需要去下载的,配置的是阿里云的镜像,把eclise的预编译给关闭,具体做法为:Project----- ...

  10. (二十六)c#Winform自定义控件-有确定取消的窗体(二)

    前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. 开源地址:https://gitee.com/kwwwvagaa/net_winform_custom_control ...