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进程 ...
随机推荐
- Daily Scrum NO.7
工作概况 今日由于时间比较充裕,没有编译作业的干扰,团员们的进度喜人.线程池.动态爬取.异常清理这三个主要开发工作已经步入尾声.其中线程池开发工作的代码已经签入,现主要在测试和优化.动态爬取今日也签入 ...
- 【MOOC EXP】Linux内核分析实验二报告
程涵 原创博客 <Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-1000029000 [操作系统是如何工作的] 教学内 ...
- 冲刺Two之站立会议2
今天我们进行了主界面部分的设置,因为它包含的部分有很多,所以就只能它拆分进行一一突破.今天主要完成了主界面的框架搭建,以及添加了需要的按钮,包括好友管理,退出登录,开启聊天通信界面的内容等.
- Git 笔记——如何处理分支合并冲突
1.前言 学习使用 Git 也有一段时间,但一直都是把 Git 当作一个代码仓库,使用的命令无非就是 clone, add, commit ,往往课程作业也没有过多人合作开发,没有体验过 Git 的分 ...
- 高效获取网页源码COM
目前获取网页源码有几种方法: 1.WebClient下载页面2.HttpWebRequest发请求获取3.com组件xmlhttp获取 三者比较:WebClient代码最少,效率最慢:xmlhttp代 ...
- 使用Samba服务程序,让linux系统之间共享文件
yum install -y cifs-utils mkdir /database 创建挂载目录 在root家目录创建认证文件(依次为SMB用户名.SMB用户密码.SMB共享域) v ...
- 【壹拾壹周】final分数分配
组名: 新蜂 组长: 武志远 组员: 宫成荣 谢孝淼 杨柳 李峤 项目名称: java俄罗斯方块NEO 发布时间:12.3 git地址:https://git.coding.net/Boxer_/ho ...
- 【大数据】Hive学习笔记
第1章 Hive基本概念 1.1 什么是Hive Hive:由Facebook开源用于解决海量结构化日志的数据统计. Hive是基于Hadoop的一个数据仓库工具,可以将结构化的数据文件映射为一张表, ...
- [代码]--给GridControl中的某列添加图片
要让GridControl的某列显示图片只需要数据源中有图片就可以正确显示 1.给DataSet添加一列,格式为image ds.Tables[].Columns.Add("SIGN&quo ...
- 关于找List的中间Node
初始值 slow = fast = head; 如果使用 fast && fast->next && fast->next->next 作为快慢指针循 ...