CodeForces - 1214D D. Treasure Island
题目链接:https://vjudge.net/problem/2728294/origin
思路:可以抽象成管道,先试试能不能找到一个通道能通到终点,
如果可以则封锁这个通道,一个石头即可,
再试试能不能找到另一个通道能到达终点,
如果可以则再用一个石头封锁这个通道。
整个题目抽象成能不能找出两个独立的通道(如果不能说明需要公用一个管道),从起点流到终点。
为了充分利用格子,最合理化找出通道,应该选择靠边的方法找格子。
#include <stdio.h>
#include <iostream>
using namespace std; const int N = (int)1e6+;
char mp[N];
int vis[N];
int n,m; inline bool check(int x,int y){
return x>=&&x<n&&y>=&&y<m;
} bool dfs(int x,int y){ if( !check(x,y) || vis[x*m+y] ) return false;
if( x*m+y == n*m- ) return true;
vis[x*m+y] = ; return dfs(x,y+) || dfs(x+,y);
} int main(){ scanf("%d%d",&n,&m); for(int i = ; i < n; i++){
scanf("%s",mp+i*m);
for(int j = i*m; j < (i+)*m; j++){ if(mp[j] == '#') vis[j] = ;
}
} bool flag = ;
for(int o = ; o <= ; o++){ vis[] = ;
if(!dfs(,)){
cout << o << endl;
flag = ;
break;
}
}
if(flag) cout << << endl; return ;
}
CodeForces - 1214D D. Treasure Island的更多相关文章
- [Codeforces 1214D]Treasure Island(dfs)
[Codeforces 1214D]Treasure Island(dfs) 题面 给出一个n*m的字符矩阵,'.'表示能通过,'#'表示不能通过.每步可以往下或往右走.问至少把多少个'.'变成'#' ...
- Gym 100971A Treasure Island BFS 思维题
A - Treasure Island Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64 ...
- D. Treasure Island
D. Treasure Island dfs大法好== 写半天bfs疯狂MLE dfs标记掉路上的一些点 然后再跑一遍dfs #include<bits/stdc++.h> using n ...
- Treasure Island DFS +存图
All of us love treasures, right? That's why young Vasya is heading for a Treasure Island. Treasure I ...
- Codeforces 106D Treasure Island 预处理前缀+暴力(水
主题链接:点击打开链接 意甲冠军: 特定n*m矩阵 # 是墙 . 和字母是平地 最多有26个字母(不反复出现) 以下k个指令. 每一个指令代表移动的方向和步数. 若以某个字母为起点,依次运行全部的指令 ...
- Treasure Island(两遍dfs)-- Codeforces Round #583 (Div. 1 + Div. 2, based on Olympiad of Metropolises)
题意:https://codeforc.es/contest/1214/problem/D 给你一个n*m的图,每次可以往右或者往下走,问你使(1,1)不能到(n,m)最少要放多少 ‘ # ’ . 思 ...
- Codeforces GYM 100114 B. Island 水题
B. Island Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100114 Description O ...
- Codeforces 540D Bad Luck Island
http://codeforces.com/problemset/problem/540/D 题目大意: 会出石头.剪刀.布的人分别有r,s,p个,他们相互碰到的概率相同,输的人死掉,问最终活下去的人 ...
- codeforces A. Orchestra B. Island Puzzle
A. Orchestra time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
随机推荐
- 安全性测试:OWASP ZAP 2.8 使用指南(三):ZAP代理设置
ZAP本地代理设置 如前文所言,ZAP的工作机制,是通过“中间代理”的形式实现. ZAP的代理设置可以从菜单中的:工具 - 选项 - Local Proxies加载. 在这里可以设置ZAP用来接受接入 ...
- (java实现)单链表
什么是单链表 在了解单链表之前,你知道什么是链表吗?如果你不知道什么是链表,可以看看我的这篇博客<链表-LinkList> 单链表是链表的其中一种基本结构.一个最简单的结点结构如图所示,它 ...
- 基于C#的机器学习--c# .NET中直观的深度学习
在本章中,将会学到: l 如何使用Kelp.Net来执行自己的测试 l 如何编写测试 l 如何对函数进行基准测试 Kelp.Net是一个用c#编写的深度学习库.由于能够将函数链到函数堆栈中,它在 ...
- Jedis 常用API使用
使用Jedis操作Redis常用的API <!-- https://mvnrepository.com/artifact/redis.clients/jedis --> <depen ...
- linux 查看文件大小命令
1.# ls -l (k) ls -l total -rw-r----- root root Oct : catalina.--.log -rw-r----- root root Oct : cata ...
- Redis的持久化机制是什么?各自的优缺点?
Redis 提供两种持久化机制 RDB 和 AOF 机制: 1.RDBRedis DataBase)持久化方式:是指用数据集快照的方式半持久化模式) 记录 redis 数据库的所有键值对,在某个时间点 ...
- PCIE DMA实现
基于Spartan-6, Virtex-5/Virtex-6/Virtex-7/7 Series FPGA PCI Express Block Endpoint模块设计PCI Express Endp ...
- 04-12 scikit-learn库之随机森林
目录 scikit-learn库之随机森林 一.RandomForestClassifier 1.1 使用场景 1.2 代码 1.3 参数 1.4 属性 1.5 方法 二.RandomForestRe ...
- 自学导航页(待续ing)
1 博客导航1.1 linuxlinux全线教程–提供了linux教程,服务器管理教程,BSD教程,还有编程语言(C/Java/Python/Perl),以及网络等全栈学习教程 1.2 存储技术NoS ...
- JavaEE——JSP开发模式(model1)
model1开发模式 工作流程: ①浏览器请求,JSP页面接收 ②JSP根据请求和JavaBean进行交互 ③JavaBean进行业务处理,JDBC操纵数据库 ④JSP将请求结果返回浏览器页面 利用m ...