编程介的小学生 2017-03-08 11:30 采纳率: 20.5%
浏览 731
已采纳

Enjoy Collisions

Given a rectangular area of size N by M which is partitioned into N*M unit squares(N columns and M rows). The four sides of the area are closed by walls (shown by the grey units in Figure 1). The coordinates of the lower-left corner unit are defined to be (1,1), and those of the upper-right corner (N,M). Inside the area there are some pillars (shown by the small blue squares in Figure 1) fixed which can be inserted into some block.

A block is either a square (denoted by (S, a) where a is the length of the side of square) or an isoceles right triangle (denoted by (T, a, style) where a is the length of its right angle's side, and style is its position). Every block has a hole which can fit a pillar in. The hole is positioned at the upper-left corner of a square block, and at the corner of the right angle of a triangle block (shown by the figures below).
Once a block fits into a pillar, it will be fixed by the pillar and can NOT move or be turned over or be rotated.

Now suppose that there is a small car (occupying 1 unit, and being represented by the red unit in Figure 1) moving from (1,1) to the upper-right corner. Whenever the car encounters a block or the wall, its moving direction will be changed. The car can only move to four directions: upper-right, lower-right, upper-left, and lower-left. When the car (red unit) moves to the upper-right direction, we have the following possible situations shown by the figures (1)-(8) (block and wall are represented by green units and a white unit is free of any barrier):
(1) upper-right turns to lower-right; (2) upper-right turns to upper-left;
(3) upper-right turns to lower-left; (4) upper-right turns to lower-right;
(5) upper-right turns to upper-left; (6) upper-right turns to lower-left;
(7) upper-right turns to lower-left; (8) continue moving to upper-right
Other cases can be deduced from the above 8 cases.

Given B pillars and B blocks, you are supposed to fix all the blocks into the area by fitting each one into a pillar. The blocks must NOT overlap each other or cross the walls. The question is that how many different ways of fixing the blocks that will guarantee the car moving back to (1,1) after finitely many steps?
The figure below shows an example of 2 blocks and 2 pillars. The numbers mark the sequential steps the car moves, and in this figure the car can indeed be back to (1,1). The 2 blocks are (s,2) and (s,1). The positions of the 2 pillars are (2,5) and (5,2).

Notice:
In case that the car can not move at all (example shown by the following figure), the fixing of the block is considered invalid.
Also note that the initial position of the car, (1,1), must NOT be occupied by any block.

Input

The first line of input contains an integer t (1<=t<=10), followed by t test cases.
The first line of each test case contains three integers N, M, and B, where 3<=N<=50, 3<=M<=50, and 1<=B<=10.
The next B lines of input are in the form of either
S sa
or
T ta style
indicating the kinds of B blocks. Here 1<=sa<=10, 2<=ta<=10, 1<=style<=4.
The next B lines give the B distinct coordinates of the pillars, in the form of
xi yi
where 1<=xi<=n and 1<=yi<=m.

Output

For each test case, output an integer which is the number of different ways of fixing the blocks such that the car can move back to (1,1).

Sample Input

2
5 5 2
S 1
S 2
2 5
5 2
4 5 2
T 2 3
S 3
3 3
4 5

Sample Output

1
0

  • 写回答

2条回答 默认 最新

  • threenewbee 2017-03-14 09:18
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 各位请问平行检验趋势图这样要怎么调整?说标准差差异太大了
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 wpf界面一直接收PLC给过来的信号,导致UI界面操作起来会卡顿
  • ¥15 init i2c:2 freq:100000[MAIXPY]: find ov2640[MAIXPY]: find ov sensor是main文件哪里有问题吗
  • ¥15 运动想象脑电信号数据集.vhdr
  • ¥15 三因素重复测量数据R语句编写,不存在交互作用
  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab