Codeforces Round #325 (Div. 2)-D. Phillip and Trains

测站坐标系、地心非惯性系、经纬高互转 目录 一、经纬高转直角坐标系互转 1.1 python代码 二、wgs84转cgcs2000的转换矩阵如下 虽然cgcs2000与wgs84差别很小,但是我比较较真,还是做了两个坐标系的转换。 一、经纬高转直角坐标系互转 此处可参考链接(百度文库用手机浏览器可以打开看全部的): (1)第四章地球椭球及其数学详解 (2)第四章椭球数学变换16节 (3)大地测量学基础[1](7)(控制) 转换公式如下: LBH转XYZ: a为半长轴,e为偏心率 XYZ转LBH: a为半长轴 阅读详情

原题链接
D. Phillip and Trains
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
The mobile application store has a new game called “Subway Roller”.

The protagonist of the game Philip is located in one end of the tunnel and wants to get out of the other one. The tunnel is a rectangular field consisting of three rows and n columns. At the beginning of the game the hero is in some cell of the leftmost column. Some number of trains rides towards the hero. Each train consists of two or more neighbouring cells in some row of the field.

All trains are moving from right to left at a speed of two cells per second, and the hero runs from left to right at the speed of one cell per second. For simplicity, the game is implemented so that the hero and the trains move in turns. First, the hero moves one cell to the right, then one square up or down, or stays idle. Then all the trains move twice simultaneously one cell to the left. Thus, in one move, Philip definitely makes a move to the right and can move up or down. If at any point, Philip is in the same cell with a train, he loses. If the train reaches the left column, it continues to move as before, leaving the tunnel.

Your task is to answer the question whether there is a sequence of movements of Philip, such that he would be able to get to the rightmost column.
这里写图片描述
Input
Each test contains from one to ten sets of the input data. The first line of the test contains a single integer t (1 ≤ t ≤ 10 for pretests and tests or t = 1 for hacks; see the Notes section for details) — the number of sets.

Then follows the description of t sets of the input data.

The first line of the description of each set contains two integers n, k (2 ≤ n ≤ 100, 1 ≤ k ≤ 26) — the number of columns on the field and the number of trains. Each of the following three lines contains the sequence of n character, representing the row of the field where the game is on. Philip’s initial position is marked as ‘s’, he is in the leftmost column. Each of the k trains is marked by some sequence of identical uppercase letters of the English alphabet, located in one line. Distinct trains are represented by distinct letters. Character ‘.’ represents an empty cell, that is, the cell that doesn’t contain either Philip or the trains.

Output
For each set of the input data print on a single line word YES, if it is possible to win the game and word NO otherwise.

Examples
input
2
16 4
…AAAAA…
s.BBB…CCCCC
…DDDDD…
16 4
…AAAAA…
s.BBB…CCCCC…
…DDDDD…
output
YES
NO
input
2
10 4
s.ZZ…
…AAABB
.YYYYYY…
10 4
s.ZZ…
…AAAABB
.YYYYYY…
output
YES
NO
Note
In the first set of the input of the first sample Philip must first go forward and go down to the third row of the field, then go only forward, then go forward and climb to the second row, go forward again and go up to the first row. After that way no train blocks Philip’s path, so he can go straight to the end of the tunnel.

Note that in this problem the challenges are restricted to tests that contain only one testset.
题意&思路:这个题有点类似于前一段时间手机上一个比较有名的游戏地铁跑酷,他的移动规则是人先向右移动一格,然后可以瞬间移动到上一格或者是下一格(如果可以),然后车会向左走两格,其实根据相对论我们可以认为车没有动而人又向右走了两步。结束的标志就是人撞上了火车或者是到达了最右边。这个问题可以用DFS+记忆化搜索来做也可以用BFS来做,我是用BFS加记忆化,将确定不可能到达右边的情况索性也认为是车。同时使用X坐标大的优先级高的优先队列来优化这个BFS。如果不加记忆化就会超时。
以下是部分测试数据

8
16 4
...AAAAA........
s.BBB......CCCCC
........DDDDD...
16 4
...AAAAA........
s.BBB....CCCCC..
.......DDDDD....
10 4
s.ZZ......
.....AAABB
.YYYYYY...
10 4
s.ZZ......
....AAAABB
.YYYYYY...
100 1
AA..................................................................................................
s...................................................A.............................................AA
..................................................................................................AA
97 23
......EEE.PPPPBBBBB.FFF..DDDDD.......VVV.......SSS......KKKK......QQQQQQ.TTTTTT......JJJ.........
s.........................HHH..........OO.....NNNNNN...CCCC..............UUUU............MMMMGGG.
...........AAAAA....LLL........................................II..................RRR...WWWWW...
100 20
.................XXXXXLL.ZZZ.............CCC..................PPPP..............SSSSS...IIIII.......
s.....WWWWWWW.................VV......KK..............RR........................................JJJJ
....QQQ...........TTTTTTT.BB...............................EEEEEEE....FFFF.DDD...YYYY......NNNNN....
100 5
............................................AAAAAA..................................................
s...................................................CCC...BBBBBBDDDDDD..............................
..................................................................EEEEEE............................
//http://codeforces.com/problemset/problem/586/D
#include <algorithm>
#include <iostream>
#include <utility>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <set>
using namespace std;

typedef long long ll;
const int MOD = int(1e9) + 7;
//int MOD = 99990001;
const int INF = 0x3f3f3f3f;
const ll INFF = (~(0ULL)>>1);
const double EPS = 1e-9;
const double OO = 1e20;
const double PI = acos(-1.0); //M_PI;
const int fx[] = {0,-1,1};
const int maxn=100 + 300;
int a[3][maxn];
int ok=0;//代表当前还没有找到
int n,k;
struct node
{
	int i,j;
	friend bool operator < (node x,node y){
		return x.j < y.j;//这样j小的在队列底
	}
};
bool can(int x,int y){
        if(a[x][y]==1 && a[x][y+1]==1 && a[x][y+2]==1) return true;
        else return false;
}
void bfs(int loci,int locj){
		priority_queue<node> q;
        q.push((node){loci,locj});
        while(!q.empty()){
                node now=q.top();
                q.pop();//取队列的首位,并删除首位
                //cout << now.i << " " << now.j << endl;
                if(a[now.i][now.j+1]==0) continue;
                bool flag=false;
                for(int i=0;i<3;i++){
                        int newi=now.i+fx[i];
                        int newj=now.j+1;
                        if(can(newi,newj)){
                                if(newj+2>=n){
                                        ok=1;
                                        return;
                                }
                                q.push((node){newi,newj+2});//新状态入队列
                                flag=true;
                        }
                }
                a[now.i][now.j]=0;
        }
}
int main(){
		int T;
		scanf("%d",&T);
		while(T--){
			memset(a,0,sizeof(a));//0 no   1 can
			scanf("%d%d",&n,&k);
			int loci=0,locj=0;
			for(int i=0;i<3;i++){
				char t;
				for(int j=0;j<n;j++){
					scanf(" %c",&t);
					if(t=='.'){
						a[i][j]=1;
					}
					else if(t=='s'){
						a[i][j]=1;
						loci=i;
						locj=j;
					}
				}
				for(int j=n;j<105;j++)
					a[i][j]=1;
			}
			ok=0;
			bfs(loci,locj);
			if(ok==1) cout << "YES" << endl;
			else cout << "NO" << endl;
		}
        return 0;
}
微信支付开发之平台给用户转账到零钱的功能 请求消息中应包含商家批次单号、转账名称、appid、转账总金额、转账总笔数、转账openid、收款用户姓名等信息。批次已受理成功,若发起批量转账的30分钟后,转账批次单仍处于该状态,可能原因是商户账户余额不足等。【转账场景ID】 该批次转账使用的转账场景,如不填写则使用商家的默认场景,如无默认场景可为空,可前往“商家转账到零钱-前往功能”中申请。【转账总笔数】 一个转账批次单最多发起一千笔转账。【商家批次单号】 商户系统内部的商家批次单号,要求此参数只能由数字、大小写字母组成,在商户系统内部唯一。 阅读详情

相关推荐

MTK平台TP驱动设备树与GPIO配置实战解析

本文详细解析了MTK平台TP驱动开发中的设备树与GPIO配置实战。通过DCT工具配置GPIO引脚,结合设备树节点定义触摸参数,并分享驱动移植、编译调试技巧及常见问题解决方案,帮助开发者快速掌握MTK触摸驱动开发核心。

ice55的博客 244

B.-Phillip and Trains ----一道差点让我猝死的题目,适合新手。

今天vj刷题上的一道BFS的题目。 做的让我痛苦,痛苦面具已经带上。 一道入门的bfs练习题,同时不考虑英语原文和物理知识,翻译过来是很容易解决的。 题目的意思是:Phillip 需要执行的三步操作是 1.先往右走一步; 2.再 考虑 向上 原地不动 向下走 3种情况(这里可以对应bfs的情况讨论!!) ; 3. (重点)最后 是 火车向左 唯一两个单位 , 根据相对运动, 相当于是 Philip 再向右移动 2个单位; 吐槽: wc,想想一下,cf都是English版本,没点英语能力,题面直接劝退!.

nttttt の blog 257

游戏开发实战:如何用旋转矩阵实现2D角色平滑转向(附Unity代码)

本文深入探讨了在Unity游戏开发中,如何运用旋转矩阵原理实现2D角色的平滑转向。文章从核心理论出发,提供了计算目标旋转、实现平滑插值(Lerp与SmoothDamp)的完整C#代码,并解决了与动画系统、物理引擎协同的常见难题,帮助开发者提升游戏操作手感与视觉流畅度。

weixin_29057237的博客 302

[CodeForces586D]Phillip and Trains

Description The mobile application store has a new game called "Subway Roller". The protagonist of the game Philip is located in one end of the tunnel and wants to get out of the other one. The tunnel...

weixin_30550271的博客 194

iOS面试题大全(附带答案)

C语言相关面试题 1.static有什么用途? 答案:在C语言中,static主要定义全局静态变量,定义局部静态变量,定义静态函数。 static 属于静态变量,使用它修饰的变量生命周期是整个源程序。 @1.在函数体内的 static 变量的作用范围为该函数体,该变量的内存只被分配一次,因此其值在下次调用时仍维持上次的值; @2.在模块内的 static 全局变量可以被模块内所有函数访问,但不能被模块外其它函数访问; @3.在模块内的 static 函数只被这一模块内的其它函数调用,这个函数的使用范围被限

IOSNF的博客 2434

Unity实时控制佳能单反拍照全流程(附EDSDK 3.6.1配置避坑指南)

本文详细介绍了在Unity中实时控制佳能单反相机进行拍照的完整流程,重点提供了EDSDK 3.6.1的配置与避坑指南。内容涵盖从SDK获取、环境搭建、相机初始化、参数设置到实现拍照控制,并深入探讨了实时取景的延迟优化方案与资源管理,旨在帮助开发者高效集成专业相机,提升AR/VR及摄影测量等应用的视觉输入质量。

go5gopher的博客 189

Phillip and Trains (dfs做更简单)

题目 有一天hzk大佬闲得蛋疼开发了一款手机游戏,名字叫“穿越隧道”。 游戏的主角小菲菲位于隧道的一端,想要离开另一端.隧道是一个3行n列的矩阵.在游戏开始时,小菲菲位于最左侧列(即第一列)的某个单元格中,此时突然出现一些小火车驶向他,每个小火车由该区域的某一行中的两个或更多相邻的单元格组成. 所有的小火车都以每秒两个单元格的速度从右向左移动,而小菲菲则以每秒一个单元格的速度从左向右移动.首先,小菲菲向右移动一个单元格,然后他要么向上或向下移动一个单元格,要么保持不动;此时所有小火车同时向左移动一个单

hjc的博客 194

周志华《机器学习》课程系列笔记——目录导航页

最近自学机器学习课程,注意到了南京大学周志华老师的课程。我是在学堂在线平台观看的,注意到b站上也有相应视频,但b站上并未获得授权,随时有消失的可能。周志华老师的网络教学视频中,与其西瓜书相比确实少了一些内容。但幸运的是,缺失的内容实际上对于初学者来说并不会产生太大影响。目前这一笔记也遵循视频内容,相比西瓜书中也会有一些缺失,敬请谅解。可能以后如果有机会和时间,我会再阅读周志华老师的书籍将缺失内容补全。一切内容敬请关注我的个人Page页面。

Sinocifengs的博客 1695

Codeforces Round #325 (Div. 2)D. Phillip and Trains BFS

D. Phillip and Trains The mobile application store has a new game called "Subway Roller". The protagonist of the game Philip is located in o...

weixin_30345055的博客 180

【毕业设计】基于雷达与深度学习的摔倒检测——雷达数据集处理

雷达原始数据是时域非平稳信号,快速傅里叶变换(Fast Fourier Transformation, FFT)不能很好地提取微多普勒效应的模式特征。因此短时傅里叶变换(Short Time Fourier Transformation, STFT)被应用于雷达信号的时频谱分析。本文主要介绍雷达数据集的预处理过程,包括时频谱图的中值滤波与 SVD 分解。

洋洋Young的博客 1811

verilog扰码器设计及仿真

本设计使用verilog语言实现扰码器设计与仿真 本工程在quartusII下实现并在modelsim下进行仿真 设计中包括加扰器和解扰器模块、仿真测试模块等. 下面是工程截图: 下面是modelsim仿真截图: 仿真代码部分可以自己设计更改,输出也会不同。 ...

QQ_778132974的博客 1734

Phillip and Trains bfs 思维

The mobile application store has a new game called "Subway Roller". The protagonist of the game Philip is located in one end of the tunnel and wants to get out of the other one. The tunnel is a recta...

weixin_41544329的博客 457

YOLOv11来了,使用YOLOv11训练自己的数据集和推理(附YOLOv11网络结构图)

YOLOv11 由 Ultralytics 在 2024 年 9 月 30 日发布, 最新的 YOLOv11 模型在之前的 YOLO 版本引入了新功能和改进,以进一步提高性能和灵活性。YOLO11 在快速、准确且易于使用,使其成为各种对象检测和跟踪、实例分割、图像分类和姿态估计任务的绝佳选择。

在职AI算法工程师,擅长计算机视觉,YOLO目标检测、分割等,擅长web、pyqt界面可视化,好内容持续更新中,来这里跟大家一起学习,共同进步 28万+

Codeforces 586D Phillip and Trains dfs —— Round #325 (Div. 2)

原题见CF 586D给一个3*n的地图,人s从最左边一列的某个位置出发,每次先向右走一步,再选择上、下、不动。接着连续的字母表示火车,均向左走两步。如此循环,人和火车不能相撞。问人是否能走到地图的最右边。人相对火车的水平距离其实是每次走了三步,火车可以不用动。 只要人走到当前地图的最右边,之后就不会再出现火车,输出YES即可。 所以先扩展一下地图,让之后n+10列均为’.’,然后dfs跑完即可。

Ugly Gardon 1344

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

Codeforces Round #325 (Div. 2) D. Phillip and Trains (BFS)

一开始看这题,还以为是DP,后来写完记忆化搜索之后发现结果怎么也不对,仔细一想,无论时间复杂度还是状态转移好像都不想DP。    后来想了一下,发现应该是BFS(DFS的盲目性太大,而BFS则可以在最早的时刻剪枝)。   所以我们不妨先用一个数组记录下所有列车在各个时间点的状态,然后用来在BFS中做判断。 细节参见代码: #include using namespace std; typede

AC_Arthur的专栏 694

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

Codeforces Round #325 (Div. 2) D. Phillip and Trains (BFS)

D. Phillip and Trains The mobile application store has a new game called "Subway Roller". The protagonist of the game Philip is located in one end of the tunnel and wants to get ou...

dexicuo5991的博客 133

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

【Codeforces Round #325 (Div. 2)】D. Phillip and Trains

Codeforces Round #325 (Div. 2) 题目D. Phillip and Trains

Johann的博客 859

Codeforces Round #325 (Div. 2) D. Phillip and Trains

水题,bfs一下即可。。。 #include using namespace std; typedef long long LL; #define mp(x, y) make_pair(x, y) const int maxn = 105; queue >q; int vis[5][maxn]; char g[5][maxn]; int n, m; bool check(int x, in

yysys 506

Codeforces Round #325 (Div. 2) D. Phillip and Trains BFS

D. Phillip and Trains Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/586/problem/D Description The mobile application store has a new game called "Subway...

weixin_30608131的博客 191

Codeforces Round #325 (Div. 2) Phillip and Trains dp

原题连接:http://codeforces.com/contest/586/problem/D 题意: 就大家都玩过地铁奔跑这个游戏(我没玩过),然后给你个当前的地铁的状况,让你判断人是否能够出去。 题解: 就首先预处理一下每个点在哪些时刻会被车子占领,然后从右向左dp一下就好 代码: #include<iostream> #include<cstring&g...

weixin_30919571的博客 115

CodeForces - 586D Phillip and Trains (BFS || DP)

The mobile application store has a new game called "Subway Roller".The protagonist of the game Philip is located in one end of the tunnel and wants to get out of the other one. The tunnel is a rectang...

←_← 388

Mobile Application Store

总结一下 Exsiting Moible Application Store [list] [*]http://store.apple.com/us [*]http://www.android.com/market/ [*]RIM Application Center. [*]http://www.orangepartner.com/ [*]http://store.ovi.co...

myrepos的专栏 214

CodeForces 586D Phillip and Trains (dfs)

D. Phillip and Trainstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe mobile application store has a new game called "Subway Roller".The protago...

Mizersy的博客 350

B. Phillip and Trains

http://codeforces.com/contest/585/problem/B 模拟 1 2 3 public class Main { 4 public static void main(String[] args) { 5 Scanner io = new Scanner(System....

ao9795的博客 226

CodeForces - 586D A - Phillip and Trains bfs

The mobile application store has a new game called "Subway Roller". The protagonist of the game Philip is located in one end of the tunnel and wants to get out of the other one. The tunnel is a recta

Marcus-Bao的个人主页 628

Codeforces 586D Phillip and Trains 题解

Codeforces 586D题解

DarkoDu的博客 442
上一篇: 各排序算法的实现及性能比较
下一篇: Codeforces Round #286 (Div. 2)-A. Mr. Kitayuta's Gift
门豪杰
博客等级 码龄11年 175粉丝 166原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

门豪杰

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值