编程介的小学生 2017-03-13 11:25 采纳率: 20.5%
浏览 938
已采纳

MatScan

Background:

Manager (M): Hey, bob, you got the manual of the new Advance Cell Matrix scanner?

Bob (B): Yeah. This machine is exciting. It can scan either horizontally or vertically in one session comparing our old machine that can do only spot test in a run. This new buddy can boost our test period like rocket.

M: When do you estimate your data can be proceeded then? I assume with the new machine you can cheer up our boss by the end of this month?

B: Hmm, I will do my best, in case he promise me a bonus. But currently I am not sure how good it can really until i run some serious tests on it.

M: Oh, really? This machine is quite expensive so I hope it can just work as it was advertised.

B: Don't worry, I will configure the machine before we run and make sure the time consumed is optimized.

M: That sounds good. Look, if you work well on this machine and by the end of this year you may be sitting in my desk.

B: And you?

M: CEO, probably.

B: ...

Bob surely wants to be the manager (and later CEO, since an ACM that can scan two directions in one session may occur soon), so you, his poor assistant must figure out the way to optimize the scan session so the time consumed is minimized. You want Bob's position, when he is gone, right?

Input format:

One integer in the first line, followed by a blank line, stating the number of test cases. There will be no more than 1024 tests.

For each test case, the first line is two integer 'rows', 'cols' (1 <= rows, cols <= 100) stating the number of rows and columns of the matrix respectively. Then 'rows' lines follow each with 'cols' characters describing the matrix. A '*' is a grid of interest and your scan line must cover it at least once. A '.' is a grid ignorable so to save time, you probably do not want to scan it. A scan goes through the matrix along its direction and can not be interrupted. All sessions take a same unit time.

The test cases will be separated by a single blank line.

Output format:

An integer reporting the optimum unit time used to finish the scan that covers all grids of interest. That many lines follow describing the detail of the configuration with 2 integers in each line, 'd' and 'k', with no leading or trailing spaces and separated with a single space. The integer 'd' is the direction to scan, for which '1' stands for horizontal scan in row direction and '2' stands for vertical scan in column direction. 'k' is the row id or column id, depending on the direction scanned as stated with 'd'. The row number is between 1 and 'rows' inclusive and the column number is between 1 and 'cols' inclusive.

All valid answer within the optimum time we expect will be accepted.

Use a single blank line to separate neighboring output blocks.

Sample input:

2

4 4
.**.
.**.
..*.
.*..

1 1
*
Sample output:

2
2 2
2 3

1
1 1
Sample hints:

Test 1: 2 scan sessions is the least as we expect. The first scan covers grids (1,2), (2,2) and (4,2) in a vertical scan at column 2. The second scan covers grids (1,3), (2,3) and (3,3), which finally completes the test. The answer
2
2 3
2 2
is also acceptable.
Test 2: One grid of interest, one session.

  • 写回答

2条回答 默认 最新

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

报告相同问题?

悬赏问题

  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法