CodeForces 586D
题意略。
将人的移动分为3步,第一步向右,第二步是行之间的变换,第三步是向右走2步,三步加在一起算作是一次移动,计入判重数组。
在第一步时有一个特殊情况:已经越过最右边的边界线,这时graph[x][y] != '.',要进行特判。
在第二步时要注意越界和撞上火车。
在第三步时有3种情况:
1.只需走1步就可以到达边界线。此时,我需要特判。
2.走2步才能到达边界线。注意graph[x][y + 1]不能是火车。
3.不能到达边界线。注意graph[x][y + 1]和graph[x][y + 2]不能是火车。
至于为什么wa这么多次,应该是我没有考虑走路的连贯性,在棋盘上走的时候都是跳跃的。
详见代码:
#include<bits/stdc++.h>
#define maxn1 30
#define maxn2 150
using namespace std; char graph[][maxn2];
int visit[][maxn2];
int n,k,T; struct point{
int x,y;
point(int a = ,int b = ){
x = a,y = b;
}
point operator+ (point p){
return point(p.x + x,p.y + y);
}
}; bool bfs(point s){
queue<point> que;
visit[s.x][s.y] = ;
que.push(s);
while(que.size()){
point temp = que.front();
que.pop();
point nxt1 = temp + point(,);
if(nxt1.y >= n - ) return true;
if(graph[nxt1.x][nxt1.y] != '.') continue;
point nxt2;
for(int i = -;i <= ;++i){
nxt2 = nxt1 + point(i,);
if(nxt2.x < || nxt2.x > || graph[nxt2.x][nxt2.y] != '.') continue;
point nxt3 = nxt2 + point(,);
if(nxt3.y < n - && graph[nxt2.x][nxt2.y + ] == '.' && graph[nxt2.x][nxt2.y + ] == '.' && visit[nxt3.x][nxt3.y] == ){
visit[nxt3.x][nxt3.y] = ;
que.push(nxt3);
}
else if(nxt2.y + >= n - && visit[nxt3.x][nxt3.y] == ){
visit[nxt3.x][nxt3.y] = ;
que.push(nxt3);
}
else if(nxt3.y >= n - && graph[nxt2.x][nxt2.y + ] == '.' && visit[nxt3.x][nxt3.y] == ){
visit[nxt3.x][nxt3.y] = ;
que.push(nxt3);
}
}
}
return false;
} int main(){
scanf("%d",&T);
while(T--){
memset(visit,,sizeof(visit));
scanf("%d%d",&n,&k);
point start;
for(int i = ;i < ;++i){
scanf("%s",graph[i]);
if(graph[i][] == 's'){
start = point(i,);
graph[i][] = '.';
}
}
printf("%s\n",bfs(start) ? "YES" : "NO");
}
return ;
}
CodeForces 586D的更多相关文章
- Codeforces 586D. Phillip and Trains 搜索
D. Phillip and Trains time limit per test: 1 second memory limit per test :256 megabytes input: stan ...
- CodeForces - 586D Phillip and Trains 搜索。vis 剪枝。
http://codeforces.com/problemset/problem/586/D 题意:有一个3*n(n<100)的隧道.一个人在最左边,要走到最右边,每次他先向右移动一格,再上下移 ...
- 【33.33%】【codeforces 586D】Phillip and Trains
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- Codeforces 586D Phillip and Trains(DP)
题目链接 Phillip and Trains 考虑相对位移. 每一轮人向右移动一格,再在竖直方向上移动0~1格,列车再向左移动两格. 这个过程相当于每一轮人向右移动一格,再在竖直方向上移动0~1格, ...
- CodeForces 586D【BFS】
题意: s是这个人开始位置:连续相同大写字母是 Each of the k trains,相应的火车具有相应的字母: '.' 代表空: 有个人在最左列,上面有连续字母代表的火车,火车从左边出去的话,会 ...
- CodeForces - 586D Phillip and Trains
这道题是一道搜索题 但是 如果没有读懂或者 或者拐过弯 就很麻烦 最多26个火车 那么每一个周期 (人走一次 车走一次) 就要更改地图 的状态 而且操作复杂 容易超时 出错 利用相对运动 计周期为 人 ...
- 【Mutual Training for Wannafly Union #1 】
A.Phillip and Trains CodeForces 586D 题意:过隧道,每次人可以先向前一格,然后向上或向下或不动,然后车都向左2格.问能否到达隧道终点. 题解:dp,一开始s所在列如 ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
随机推荐
- Centos6.9安装部署nginx服务器
(一)依赖包安装 首先,gcc,pcre,zlib,openssl安装一边(可以用非-devel,但是嫌麻烦....用非-devel的看这个链接) yum -y install gcc ------ ...
- J.U.C atomic AtomicInteger解析
很多情况下我们只是需要简单的,高效,线程安全的递增递减方法.注意,这里有三个条件:简单,意味着程序员尽可能少的底层或者实现起来比较简单:高效,意味着耗用资源要少,程序处理速度要快: 线程安全也非常重要 ...
- 工厂模式Java
一.工厂模式主要是为创建对象提供过渡接口,以便将创建对象的具体过程屏蔽隔离起来,达到提高灵活性的目的. 工厂模式在<Java与模式>中分为三类:1)简单工厂模式(Simple Factor ...
- 导入Mybatis_Spring项目遇到的问题
1. 问题: jdk版本不匹配 解决方法:首先 到项目空间的 .setting文件中找到 org.eclipse.wst.common.project.facet.core.xml 修改参 ...
- CentOS7.x机器安装Azure CLI2.0
安装Azure CLI 2.0的前提是:机器中必须有 Python 2.7.x 或 Python 3.x.如果机器中没有其中任何一个Python的版本,请及时安装 1.准备一台CentOS 7.3的机 ...
- springmvc配置文件配置的事务作用范围
作用于service,不是controller,也不是mapper.所以,要保证原子性,就放在一个serviceimpl里,而不要放在一个controller 里 第一次与数据库打交道时,事务开启,s ...
- C# WinForm调用UnityWebPlayer Control控件 <学习笔记1>
工具 1.三维场景 Unity 5.0.2f1 2.开发环境Microsoft Visual Studio 2010 3.需要使用的控件 UnityWebPlayer Control 出现的问题及解决 ...
- java获取昨天的日期
Calendar cal = Calendar.getInstance(); cal.add(Calendar.DATE, -1); String yesterday = new ...
- awk取每行最大值
需求 有一个数字文本,每行都是数字,以空格分开:现在需要将每行中最大值取出来 文本如下: [root@localhost ~]#cat urfile 1 1 2 1 2 1 1 3 1 使用awk解决 ...
- 关于awk的多文件处理
关于awk的多文件处理: awk的数据输入有两个来源,标准输入和文件,后一种方式支持多个文件,如1.shell的Pathname Expansion方式:awk '{...}' *.txt # *.t ...