D. Treasure Island

dfs大法好==

写半天bfs疯狂MLE

dfs标记掉路上的一些点

然后再跑一遍dfs

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define sc(x) scanf("%I64d",&x);
#define read(A) for(int i=0;i<n;i++)scanf("%I64d",&A[i]);
#define endl '\n'
#define fi first
#define se second
#define si signed
#define P pair<si,si>
#define pb push_back
#define maxn 1000000+100
bool A[maxn];
int n,m;
queue<P>q;
P fa[maxn];
bool vis[maxn];
int cnt=;
bool bfs()
{
while(!q.empty())q.pop();
q.push(P(,));
while(!q.empty())
{
P a=q.front();
q.pop();
si x=a.fi;
si y=a.se;
//B[x*m+y]++;
if(x==n-&&y==m-)
{
// cnt++;
//f=0;
return false;
}
if(x+<n)
{
if(A[(x+)*m+y]==)
{
fa[(x+)*m+y]=P(x,y);
q.push(P(x+,y));
}
}
if(y+<m)
{
if(A[x*m+y+]==)
{
fa[x*m+y+]=P(x,y);
q.push(P(x,y+)); }
}
} return true;
//else return false;
}
bool dfs(int x,int y)
{
vis[x*m+y]=;
int a=x+;
if(x==n-&&y==m-)return true;
if(a<n&&!vis[a*m+y]&&A[a*m+y]==){
if(dfs(a,y))return true;
}
int b=y+;
if(b<m&&!vis[x*m+b]&&A[x*m+b]==){
if(dfs(x,b))return true;
}
return false; }
signed main()
{
sc(n);
sc(m);
int t=;
for(int i=; i<n; i++)
{
getchar();
for(int j=; j<m; j++)
{
A[i*m+j]=(getchar()=='#'?:);
t+=A[i*m+j];
}
}
if(t==&&(n==||m==)){
cout<<<<'\n';
return ;
}
if(t==)
{
cout<<<<'\n';
return ;
}
if(n==||m==){
cout<<<<'\n';
return ;
}
int ans=;
if(!dfs(,)){
cout<<<<'\n';
return ;
}
vis[]=vis[(n-)*m+m-]=;
if(!dfs(,)){
cout<<<<'\n';
return ;
}
cout<<<<'\n';
/* if(bfs())
{
cout<<0<<'\n';
return 0;
}
//cout<<B[1*m+2]<<endl;
P x=fa[(n-1)*m+m-1];
si c,d;
while(true){
c=x.fi,d=x.se;
if(c==0&&d==0)break;
x=fa[c*m+d];
A[c*m+d]=1;
}
if(bfs()){
cout<<1<<'\n';
return 0;
}
cout<<ans<<'\n';
*/
}

D. Treasure Island的更多相关文章

  1. Gym 100971A Treasure Island BFS 思维题

    A - Treasure Island Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64 ...

  2. [Codeforces 1214D]Treasure Island(dfs)

    [Codeforces 1214D]Treasure Island(dfs) 题面 给出一个n*m的字符矩阵,'.'表示能通过,'#'表示不能通过.每步可以往下或往右走.问至少把多少个'.'变成'#' ...

  3. Treasure Island DFS +存图

    All of us love treasures, right? That's why young Vasya is heading for a Treasure Island. Treasure I ...

  4. 【Gym 100971A】Treasure Island

    题意 题目链接给你一个地图,'#'代表水,'.'代表陆地,'?'代表擦去的地图,可能是'#'也可能是'.'.地图中本该只有一块相连的陆地,若只有一种方案则输出确定的地图.若有多种方案,则输出‘Ambi ...

  5. Codeforces 106D Treasure Island 预处理前缀+暴力(水

    主题链接:点击打开链接 意甲冠军: 特定n*m矩阵 # 是墙 . 和字母是平地 最多有26个字母(不反复出现) 以下k个指令. 每一个指令代表移动的方向和步数. 若以某个字母为起点,依次运行全部的指令 ...

  6. CodeForces - 1214D D. Treasure Island

    题目链接:https://vjudge.net/problem/2728294/origin 思路:可以抽象成管道,先试试能不能找到一个通道能通到终点, 如果可以则封锁这个通道,一个石头即可, 再试试 ...

  7. 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)最少要放多少 ‘ # ’ . 思 ...

  8. Codeforces1214D. Treasure Island (dp + Hash)

    题目链接:传送门 思路: 仔细观察可以发现,答案最多就是2,只要把(2,1)和(1,2)堵住就可以了. 答案是0的情况就是初始状态下,(1,1)就已经不可达(n,m)了,很好判断. 所以重点就是区分答 ...

  9. libconfig第二篇----两个小例子

    本文只看粗体即可,太多catch语句.两个例子均来自libconfig包的example文件夹下面,. 例子一: #include <iostream> #include <ioma ...

随机推荐

  1. [转帖].NET Core 项目指定SDK版本

    .NET Core 项目指定SDK版本 https://www.cnblogs.com/stulzq/p/9503121.html 一. 版本里的坑 自从 .NET Core 2.1.0版本发布以后, ...

  2. webpack的插件 http-webpack-plugin。 webpack-dev-server

    自动的生成: bundle.js  和 index.html 在该项目的目录下:npm init -yes npm install vue -D npm install webpack@3.12.0 ...

  3. 手撕ES6--Promise

    手撕ES6--Promise:https://www.jianshu.com/p/0925eae38d2c 手写一个Promise,附源码分析:https://blog.csdn.net/weixin ...

  4. Java作业 题目:16版.真实员工数统计

    题目:16版.真实员工数统计 该资源支持按部自动给分,评分规则如下: sjkdfhslkfdhdsiog函数定义测试 sjkdfhslkfdhdsiog函数定义测试 sjkdfhslkfdhdsiog ...

  5. 对Elastic集群内部配置TLS加密通信及身份验证

    1.介绍 官方宣布从6.8和7.1开始,免费提供多项安全功能.其中包括tls加密通信,基于角色访问控制等功能. 可以使用企业CA证书来完成这一步骤,但是一般情况下,我们可以通过elasticsearc ...

  6. 使用filebeat收集日志传输到redis的各种效果展示

    0 环境 Linux主机,cengtos7系统 安装有openresty软件,用来访问生成日志信息 1.15.8版本 安装有filebeat软件,用来收集openresty的日志 7.3版本 安装有r ...

  7. Git命令的总结

    Git 是当前最流行的版本控制程序之一,文本包含了 Git 的一些基本用法 创建 git 仓库 初始化 git 仓库 mkdir project  # 创建项目目录cd project  # 进入到项 ...

  8. 在Linux上安装tomcat和JDK

    1.tomcat的安装 a.#cd download(进入download文件夹) b.#wget http://111.23.5.142:82/mirrors.hust.edu.cn/apache/ ...

  9. 对应关系,以及Module作用

    register 8101---10086 gateway 8201---10010 item-service 8301---8081 manage-web 4901---9001 npm start ...

  10. host.conf - 解析配置文件

    DESCRIPTION (描述) 文件 /etc/host.conf 包含了为解析库声明的配置信息. 它应该每行含一个配置关键字, 其后跟着合适的配置信息. 系统识别的关键字有: order, tri ...