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进程 ...
随机推荐
- PAT甲题题解-1009. Product of Polynomials (25)-多项式相乘
多项式相乘 注意相乘结果的多项式要开两倍的大小!!! #include <iostream> #include <cstdio> #include <algorithm& ...
- Daily Scrumming* 2015.12.10 今天集体请假一天
今天由于所有成员均在进行编译原理实验的相关工作,全体请假一天.......
- 20135220谈愈敏Blog5_系统调用(下)
系统调用(下) 谈愈敏 原创作品转载请注明出处 <Linux内核分析>MOOC课程 http://mooc.study.163.com/course/USTC-1000029000 给Me ...
- Team Work Ⅱ
Regal-Lighting团队设计 分工思考 本次大作业我的分工定位是:Unit及子类,主要设计实现建筑类的功能. 首先王者光耀这款游戏所需要的建筑分为三类: 1.防御塔:有一定的血量,血量为0时破 ...
- Day Five
站立式会议 站立式会议内容总结 442 今天:编写具体计划的界面 遇到的问题:相对布局.绝对布局理解不够深刻 明天:完成设定计划时间的功能 331 今天:添加书籍/计划按钮,添加书籍时有一个文件选择 ...
- springmvc下载文件
Controller内代码: @RequestMapping(value = "/upload") public ResponseEntity<byte[]> uplo ...
- JetBrains系列WebStorm等中文输入法无法跟随光标的问题的解决办法
参考:https://blog.csdn.net/wang414300980/article/details/79537875 电脑配置: 解决这个问题的思路就是修改启动软件的JDK,有以下几个方法: ...
- 怎么判断pagecontrol下的TabSheet是否打开还是关闭求答案
if pagecontrol.activepage=TabSheet1 then是在当前显示页------解决方案------------------------------------------- ...
- Vue-router的基本用法
刚学习vue不久,就接触了路由这个好东西.下面简单聊聊vue-router的基本用法. 一.路由的概念 路由,其实就是指向的意思,当我点击页面上的home按钮时,页面中就要显示home的内容,如果点击 ...
- LOJ#6118 鬼牌
\(\rm upd\):是我假了...这题没有爆精...大家要记得这道题是相对误差\(10^{-6}\)...感谢@foreverlasting的指正. 题是好题,可是标算爆精是怎么回事...要写的和 ...