如何利用C语言编程实现对数列的搜索问题,采用C语言代码的编写的方式是怎么做?

Problem Description
“Frogger” was one of the first really popular arcade games after it was introduced by SEGA in 1981. The game consists of helping a frog cross a multi-lane motorway without getting run over by a car. You are given a view of an n-lane motorway where each lane consists of m different spaces
that can either be empty or be occupied by a car. On each side of the motorway is a curb on which the frog can move freely. In the traffic lanes the frog can only move on the spaces not occupied by cars. The motorway is constructed in such a way that the direction in which the cars travel
alternates between the lanes, with cars in the first lane (the one closest to the starting point of the frog) moving to the right. The cars never switch lanes and only move one step forward in each turn. To ensure a steady supply of traffic, a car that reaches the boundary of its lane is reentered at the opposite end of its lane.
[/图片/]
In one turn of the game all the cars move one step in their assigned direction while the frog can either move one step to the right or to the left, or one step up or down (between lanes or between the curb and the adjoining lane), or it can stand still. Contrary to the cars the frog cannot “wrap-around” i.e. move in one step between the first and last position of a lane or a curb.

The frog and the cars move simultaneously. Thus the frog can move to a space given that there will be no car on it in the next round. If the frog is on the same space at the same time as a car it is run over and dies. Note that the frog can jump over an adjacent approaching car in the same lane as itself.

Your job is to write a computer program that will calculate the minimum number of turns needed for the frog to get from its starting position on the curb to its final position on the curb on the other side of the road or to determine that this is not possible within a given number of rounds.

Input
First there will be a line containing the number of scenarios you are asked to help the frog in. For each scenario there will first be a line containing a positive integer x <= 10^5 giving the maximum number of rounds that can be used. The next line contains the number of lanes n, 1 <= n <= 20, and the length of each lane m, 1 <= m <=50. Each of the next n + 2 lines will contain a string of m characters. The character X indicates a car, the character O (letter O) indicates a free space, the character F gives the starting position of the frog, and the character G gives the final destination of the frog. The first line indicates the destination curb, consisting of O’s and exactly one G while the last line gives the starting curb consisting of O’s and exactly one F, while the intermediate lines each represent one lane of the motorway.

Output
The output will be one line per scenario, either giving the minimum number of turns needed before the frog can get from its starting position to the final position without getting run over by a car or a statement indicating that this was not possible within the maximum number of allowed turns.

Sample Input
2
10
4 4
OOGO
XXOO
XOOX
XXOO
XXOO
OOFO
2
2 2
OG
XX
OO
FO

Sample Output
The minimum number of turns is 9.
The problem has no solution.

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!

相似问题

2
C++语言编程 单调递增最长子序列
2
求数列的和,用C语言,谢谢
1
C语言求数列的的第n项的和
1
一个数列递推求解的问题,C语言数据结构怎么解决这个问题呢?
0
计算最小的删除的步数,结果是一个数列怎么计算的?采用C语言
0
等差数列的问题,采用C 语言如何才能进行求解呢??
1
采用C语言解决这个问题,求区间数列的问题怎么实现?
0
一个数列的递推的问题,怎么利用C语言和数据结构解决,最大值是K^2
2
求解一个和平方数列求和有关的解法的问题,采用C语言解决这个问题的思路实现怎么做?
0
数列递增序列,递减序列,数组实现,计算不同的颜色,使用的C语言谢谢
1
一个数列数组的求和再求比率的问题,如何利用C语言的方法编程算法解决
0
数列递推公式的实现,采用C语言的运用循环的方式,如何实现这个问题的解决?
0
数列级数的极值的计算的一个问题,请问是如何利用C语言的编程代码实现的呢
0
兔子繁殖的数列的问题,运用C语言的技术如何才能解决的?
0
综合运用C语言的编程的技术如何解决这里的数列求和的算法问题呢
0
数列对的问题,如何运用C语言的方式作答,利用C语言如何解决这个问题
0
请教各位神人看下这里的C语言如何才能高效解决楼梯数列推导的问题
0
这个数据结构问题运用数列递推的思路怎么使用C语言解决这个问题
0
数列整数相邻判断的问题,如何利用C语言的功能去实现的
0
判断数列求和是否超过了最大值上限,用C语言的形式编程实现