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. Hbase的几个关键问题(转自log.csdn.net/javastart/article/details/43772575)

    什么是HBase?何时用HBase?与Hive.Pig的区别?HBase的结构为何HBase速度很快?HBase常用的操作有哪些?HBase的一些配置和监控 什么是HBase? HBase,是Hado ...

  2. python告诉你啥是佩奇

    被<啥是佩奇>这支广告片刷屏了. 佩奇明明是个喜剧角色, 但是看哭了所有人. <啥是佩奇>??? 效果图如下: # -*- coding:utf-8 -*- from turt ...

  3. 一个Accecc_Token生成和缓存和读取类,微信/小程序开发必须学

    Access_Token是调用微信和小程序各种接口的临时凭证,有效期2小时(7200秒),很多接口都需要调用access_token接口生成一个access_token的,例如微信支付,微信分享,公众 ...

  4. DAX/PowerBI系列 - 累计总计(Cumulative Total, Running Total)

    DAX/PowerBI系列 - 累计总计(Cumulative Total) 2017/07/23 更新:B列公式(见最后) 2019/08/08 更新:在可视化数据的时候,一定要选择日期维度的日期列 ...

  5. 084、Prometheus 到底NB在哪里?(2019-05-06 周一)

    参考https://www.cnblogs.com/CloudMan6/p/7709970.html   本节学习Prometheus的核心,多维数据模型   比如要监控容器 webapp1 的内存使 ...

  6. 使用python 实现 微信好友 个性签名 并 制作 词云图

    环境搭建: pip install itchat numpy wordcloud matplotlib jieba 先把上面的几个包安装完成,直接上代码 import itchat from itch ...

  7. char转int,int转char

    char转int 1) '; if (Character.isDigit(ch)){ // 判断是否是数字 int num = Integer.parseInt(String.valueOf(ch)) ...

  8. 获取url中参数值

    function GetRequest() {var url = window.location.href; //获取url中"?"符后的字串var theRequest = ne ...

  9. java 统计字符串中连续重复的字符,并得出新字符串

    题目: 比如输入为aaabbc,输出a3b2c1 完整解答: public class Other { static String func(String str) { StringBuffer re ...

  10. AIX中物理卷管理

    1.物理卷管理   1.1物理卷区域的分布 按照磁头在硬盘上的读写速率不同可以把硬盘划分成几个不同级别的区域.因此逻辑卷对应的PP在哪一个级别的区域上,对逻辑卷的读写速率影响很大. 硬盘的截面分为5个 ...