题目链接:

https://cn.vjudge.net/contest/254150#problem/F

wa代码:

#include<iostream>
#include<string>
#include<cstring>
#include<queue>
#include<stdio.h>
#include<stack>
#include<map>
#include<stack>
using namespace std;
# define maxn 100
char a[10][maxn][maxn];
int vis[maxn][maxn][maxn];
int n,m,k;
int f[2][4]= {{1,-1,0,0},{0,0,1,-1}};
struct node
{
int x,y,z,step;
node(int xx,int yy,int zz,int tt)
{
z=xx;
x=yy;
y=zz;
step=tt;
}
};
bool judge(int s1,int s2)
{
if(s1>=0&&s1<n&&s2>=0&&s2<m)return true;
return false;
}
bool bfs(int t1,int t2,int t3)
{
memset(vis,0,sizeof(vis));
queue<node>q;
while(!q.empty())q.pop();
q.push(node(t1,t2,t3,0));
vis[t1][t2][t3]=1;
while(!q.empty())
{
node temp=q.front();
q.pop();
if(a[temp.z][temp.x][temp.y]=='P')
{
if(temp.step<=k)
return true;
return false;
}
for(int i=0; i<4; i++)
{
int x=temp.x+f[0][i];
int y=temp.y+f[1][i];
if(judge(x,y)&&vis[temp.z][x][y]==0&&a[temp.z][x][y]!='*')
{
vis[temp.z][x][y]=1;
if(a[temp.z][x][y]=='#')
{
if(temp.z==0)
{
if(a[1][x][y]!='*'&&a[1][x][y]!='#'&&vis[1][x][y]==0)
{
q.push(node(1,x,y,temp.step));
vis[1][x][y]=1;
}
}
else if(temp.z==1)
{
if(a[0][x][y]!='*'&&a[0][x][y]!='#'&&vis[0][x][y]==0)
{
q.push(node(0,x,y,temp.step));
vis[0][x][y]=1;
}
} }
else
{
q.push(node(temp.z,x,y,temp.step+1));
}
}
}
}
return false;
}
int main()
{
int T;
cin>>T;
while(T--)
{
int t1,t2,t3;
memset(a,'\n',sizeof(a));
cin>>n>>m>>k;
for(int i=0; i<2; i++)
{
for(int j=0; j<n; j++)
{
for(int l=0; l<m; l++)
{
cin>>a[i][j][l];
if(a[i][j][l]=='S'){
t1=i;
t2=j;
t3=l;
}
}
}
}
if(bfs(t1,t2,t3))
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
return 0;
}

AC代码:

#include<iostream>
#include<string>
#include<cstring>
#include<queue>
#include<stdio.h>
#include<stack>
#include<map>
#include<stack>
using namespace std;
# define maxn 15
char a[2][maxn][maxn];
int vis[maxn][maxn][maxn];
int n,m,k;
int f[2][4]= {{1,-1,0,0},{0,0,1,-1}};
struct node
{
int x,y,z,step;
node(int xx,int yy,int zz,int tt)
{
z=xx;
x=yy;
y=zz;
step=tt;
}
};
bool judge(int s1,int s2)
{
if(s1>=0&&s1<n&&s2>=0&&s2<m)return true;
return false;
}
bool bfs(int t1,int t2,int t3)
{
memset(vis,0,sizeof(vis));
queue<node>q;
while(!q.empty())q.pop();
q.push(node(t1,t2,t3,0));
vis[t1][t2][t3]=1;
while(!q.empty())
{
node temp=q.front();
q.pop();
if(a[temp.z][temp.x][temp.y]=='P')
{
if(temp.step<=k)
return true;
return false;
}
if(a[temp.z][temp.x][temp.y]=='#')//原来一直wa的原因就在这里,应该是先判断,再去跑四个方向,否则的话,如果先跑四个方向再去判断的话,这样步数就会少算一步。
{
if(temp.z==0)
{
if(a[1][temp.x][temp.y]!='*'&&a[1][temp.x][temp.y]!='#'&&vis[1][temp.x][temp.y]==0)
{
q.push(node(1,temp.x,temp.y,temp.step));
vis[1][temp.x][temp.y]=1;
}
}
else if(temp.z==1)
{
if(a[0][temp.x][temp.y]!='*'&&a[0][temp.x][temp.y]!='#'&&vis[0][temp.x][temp.y]==0)
{
q.push(node(0,temp.x,temp.y,temp.step));
vis[0][temp.x][temp.y]=1; }
}
}
else
{
for(int i=0; i<4; i++)
{
int x=temp.x+f[0][i];
int y=temp.y+f[1][i];
if(judge(x,y)&&vis[temp.z][x][y]==0&&a[temp.z][x][y]!='*')
q.push(node(temp.z,x,y,temp.step+1)),vis[temp.z][x][y]=1;
}
}
}
return false;
}
int main()
{
int T;
cin>>T;
while(T--)
{
int t1,t2,t3;
memset(a,'\n',sizeof(a));
cin>>n>>m>>k;
for(int i=0; i<2; i++)
{
for(int j=0; j<n; j++)
{
for(int l=0; l<m; l++)
{
cin>>a[i][j][l];
if(a[i][j][l]=='S')
{
t1=i;
t2=j;
t3=l;
}
}
}
}
if(bfs(t1,t2,t3))
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
return 0;
}

F - A计划的更多相关文章

  1. Windows任务计划程序起始于参数自动修改

    Windows任务计划程序建立后,手工运行可以成功,但计划任务自动运行却不能成功,搜索网络,原来是起始于参数没有配置,这个参数的英文名字是start-in.它保证任务计划程序的WorkingDirec ...

  2. windows2003安全加固脚本

    @echo off title= Windwos/index.html' target='_blank'>Windows Security echo. echo **************** ...

  3. svn 批量更新 bat脚本

    由于有多个程序放在svn上管理,每天都要进入相应的目录进行svn 更新操作,现在写了一个简单的脚本进行批量自动更新. Code@echo off @echo ********************* ...

  4. nginx配置文件详解----第一篇【访问与错误日志】

    error_log错误日志    access_log访问日志 log_format指令 语法: log_format name string …;默认值: log_format combined “ ...

  5. 案例分析——Who is the king of handwriting notes?

    案例分析--Who is the king of handwriting notes? 项目 内容 这个作业属于那个课程 2021春季学期软件工程(罗杰.任健) 这个作业的要求在哪里 案例分析 我在这 ...

  6. Windows核心编程 第五章 作业(上)

    第5章 作 业 通常,必须将一组进程当作单个实体来处理.例如,当让 Microsoft Developer Studio为你创建一个应用程序项目时,它会生成 C l . e x e,C l . e x ...

  7. Mysql_以案例为基准之查询

    查询数据操作

  8. F的ACM暑期集训计划

    暑假的知识计划(补充中...) 1.数论相关 (7days) 待完成 多项式同余方程/高次同余方程/欧拉函数/克莱姆法则/高斯消元/莫比乌斯反演/伪素数判定/baby-step-gaint-step ...

  9. Linux计划任务.md

    crond crond是linux下用来周期性的执行某种任务或等待处理某些事件的一个守护进程,与windows下的计划任务类似,当安装完成操作系统后,默认会安装此服务工具,并且会自动启动crond进程 ...

随机推荐

  1. JavaScript高级程序设计学习笔记2

    垃圾收集原理: 找出不再使用的变量,然后释放其内存. js中最常用的垃圾收集方法是标记清除,当变量进入环境时,就将变量标记为“进入环境”,当变量离开环境时,将其标记为“离开环境”,最后由垃圾收集器完成 ...

  2. 20135202闫佳歆--week3 构造一个简单的Linux系统MenuOs--学习笔记

    此为个人学习笔记存档 week 3 构造一个简单的Linux系统MenuOs 复习: 计算机有三个法宝:存储程序计算机,函数调用堆栈,中断 操作系统有两把剑: 1.中断上下文的切换,保存现场和恢复现场 ...

  3. Leetcode题库——46.全排列

    @author: ZZQ @software: PyCharm @file: permute.py @time: 2018/11/15 19:42 要求:给定一个没有重复数字的序列,返回其所有可能的全 ...

  4. linux下php环境的装配以及php storm的链接

    linux下php环境的装配以及php storm的链接 本次安装在deepin系统下完成 一.安装LAMP组合 Linux+Apache+Mysql+php 直接命令 sudo apt-get in ...

  5. spring整合redis(jedis)

    真是一步一个坑阿,学点新技术,这么难,这个异常: java.lang.IllegalStateException: Could not load TestContextBootstrapper [nu ...

  6. Linux下搭建testlink1.9.17

    如果只是要搭建testlink服务的话,建议使用testlink的集成安装包,能避免很多坑 下载地址:https://bitnami.com/stack/testlink/installer 下载好后 ...

  7. 打包spring项目遇到的坑 Unable to locate Spring NamespaceHandler for XML schema ……shcema/context 产生的原因及解决方法

    图1 图2 问题原因:导致该问题的原因就是打包的时候,同时将 spring-context 和 spring-aop包提取到了我们的程序应用的包中,在package过程中,这2个依赖包的 XML sc ...

  8. php内置函数分析之str_pad()

    PHP_FUNCTION(str_pad) { /* Input arguments */ zend_string *input; /* Input string 输入字符串*/ zend_long ...

  9. memcache安装以及php_memcache.dll 扩展安装

    php_memcache.dll扩展下载地址:http://windows.php.net/downloads/pecl/releases/memcache/3.0.8/ 下载注意事项:选择匹配自己环 ...

  10. SQL基本概念

    目录 什么是SQL? DDL(Data Definition Language,数据定义语言) 创建数据库(CREATE) 创建表(CREATE) 删除表(DROP) 更新表(ALTER) DML(D ...