F - A计划
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计划的更多相关文章
- Windows任务计划程序起始于参数自动修改
Windows任务计划程序建立后,手工运行可以成功,但计划任务自动运行却不能成功,搜索网络,原来是起始于参数没有配置,这个参数的英文名字是start-in.它保证任务计划程序的WorkingDirec ...
- windows2003安全加固脚本
@echo off title= Windwos/index.html' target='_blank'>Windows Security echo. echo **************** ...
- svn 批量更新 bat脚本
由于有多个程序放在svn上管理,每天都要进入相应的目录进行svn 更新操作,现在写了一个简单的脚本进行批量自动更新. Code@echo off @echo ********************* ...
- nginx配置文件详解----第一篇【访问与错误日志】
error_log错误日志 access_log访问日志 log_format指令 语法: log_format name string …;默认值: log_format combined “ ...
- 案例分析——Who is the king of handwriting notes?
案例分析--Who is the king of handwriting notes? 项目 内容 这个作业属于那个课程 2021春季学期软件工程(罗杰.任健) 这个作业的要求在哪里 案例分析 我在这 ...
- Windows核心编程 第五章 作业(上)
第5章 作 业 通常,必须将一组进程当作单个实体来处理.例如,当让 Microsoft Developer Studio为你创建一个应用程序项目时,它会生成 C l . e x e,C l . e x ...
- Mysql_以案例为基准之查询
查询数据操作
- F的ACM暑期集训计划
暑假的知识计划(补充中...) 1.数论相关 (7days) 待完成 多项式同余方程/高次同余方程/欧拉函数/克莱姆法则/高斯消元/莫比乌斯反演/伪素数判定/baby-step-gaint-step ...
- Linux计划任务.md
crond crond是linux下用来周期性的执行某种任务或等待处理某些事件的一个守护进程,与windows下的计划任务类似,当安装完成操作系统后,默认会安装此服务工具,并且会自动启动crond进程 ...
随机推荐
- 初始化Weex项目遇到的问题记录
Weex 提供了一个命令行工具 weex-toolkit 来帮助开发者使用 Weex.它可以用来快速创建一个空项目.初始化 iOS 和 Android 开发环境.调试.安装插件等操作. 目前 weex ...
- Linux内核学习总结(final)
Linux内核学习总结 符钰婧 原创作品转载请注明出处 <Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-1000029000 ...
- 跟踪分析Linux内核的启动过程小解
跟踪分析Linux内核的启动过程 “20135224陈实 + <Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-1000029 ...
- 第二阶段团队冲刺——One
个人任务: 司宇航:处理第一次启动服务器500的问题. 季方:优化cookie第一次运行出错的问题. 王金萱:修改注册界面. 马佳慧:修改登录界面. 站立会议: 任务看板和燃尽图:
- 第三次spring冲刺2
完成了对错题的收集,和做错题的功能,运用了android自带的SQLite数据库.
- nginx转发swoole以及nginx负载
nginx作为静态服务器同时转发swoole配置: location /{root //静态文件目录;index index.html index.htm;//默认首页 if(!-e $request ...
- TestNG简单介绍以及安装—学习笔记1
TestNG是什么 到这里,大家肯定已经运行了一些关于Selenium的测试用例了(这里主要是站着一个自动化测试工程师的角度来看待TestNG的,所以这里所说的也都是基于Web测试的验证点来说的,而不 ...
- PPT 遥控器
1. 下载 最新版本: 百度袋鼠输入: http://daishu.baidu.com/?from=pptweb 百度PPT遥控器:http://ppt.baidu.com/ 2. 安装过程忽略 3. ...
- springMVC返回给页面参数的三种形式
- photoshop cc 2018破解补丁(pscc2018注册机) 附使用方法
1.下载破解程序 破解文件自行到 http://www.ddooo.com/softdown/109954.htm 下载 博主可以到本博客的文件-->pscc2018zcj_109954.ra ...