编程介的小学生 2017-12-11 04:22 采纳率: 20.5%
浏览 861
已采纳

Ice-Skating

Problem Description
FJ becomes interested in ice-skating these days. Every weekends, he goes to the rink in his town. The rink is a rectangle that made up of r rows and c colomns of small squares. Some of squares are damaged and skating on these squares are forbidden.

FJ is a beginner, and he can only do a sequence of k actions one after another. One action means skating forward at most l squares (Doesn't include the square he start at) in a certain direction (Up, Down, Left and Right). Notice that he can't skate on broken squares.

Now the problem is: Given the rink and the sequence of actions, how long can FJ skating at most.

Input
The first line of input file is a single integer T (1 ≤ T ≤ 10) - the number of test cases. For each test case, in the first line there are 5 integers: r, c, x, y, k. The meaning of r, c and k are described as above. x and y means FJ is at the square in the x-th row (counting from the top and start from 1) and y-th colomn (counting from the left side and start from 1). Then there are r lines, describing the rink - '.' means good squares, and 'x' means broken squares. Then there are k lines, giving the k actions in order. Each of these lines contain 2 integers: l and d, d ∈ {1, 2, 3, 4}, 1 represent upward, 2 represent left, 3 represent downward and 4 represent right.

(1 ≤ r, c ≤ 200; 1 ≤ k ≤ 200);

Output
Output a single integer, the maxmum number of square FJ can skate throuth. If FJ skates through a square twice, count twice.

Sample Input
1
4 5 4 1 3
..xx.
.....
...x.
.....
3 4
2 1
2 2

Sample Output
6

  • 写回答

1条回答 默认 最新

  • threenewbee 2018-11-16 11:34
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。