2288. Pay per Paper

单点时限: 2.0 sec

内存限制: 256 MB

Nowadays some discos no longer use cash when they sell drinks at the bar but hand out credit cards made of paper to their guests. When someone buys a drink the price is marked on the credit card by stamping one (or more) hole(s) to the section(s) of the card that indicate the corresponding price. When the guest leaves he or she puts his or her card into a machine that detects these holes and calculates the total price (including the entrance fee).

It is your job to write a program that receives an (ASCII :-) picture of such a paper card and determines the total amount a guest has to pay.

Each picture of a paper card is of the following form:

…#…#…

…#…#O..

…#..O#O..

…#…#…

…#…#…

…#.O.#…

where the number of columns and rows may vary in different test cases (in this test case the card has three colums and two rows). A section is always a 3x3 grid of dots (“.”) which is seperated from the other sections by the “#”-sign. A section is considered to be marked if and only if it contains AT LEAST one pixel that is a hole (“O” NOT zero).

The columns indicate the prices of the sections, the first column stands for a price of 1 DM, the second for 2 DM and so on. The rows provide only additional room to mark a certain price more than once. In this example the guest has ordered drinks (or - very unlikely - food :-) for 2 x 2 DM + 1 x 3 DM = 7 DM. The entrance fee is NOT marked in the card but of course added to the total price. The last aspect you have to consider is that the disco defines a certain amount of “minimum consumption” (for instance 5 DM) which is a lower bound for the money a guest ‘has’ to spend for drinks (even if he or she consumes less he or she has to pay this “minimum consumption”-fee.

输入格式

The input consists of several test cases where the number n of test cases is given in the first line. For each test case there are four non-negative integers. First the entrance fee, second the minimum-consumption fee (as described above), third the columns of the paper card and fourth the rows of the paper card (the rows and colums are both positive so don’t bother treating degenerated cases :-). Then an ASCII picture of the paper card is given which has exactly as much columns and rows as specified for that test case.

输出格式

The output should consist of two lines. The first one should contain the number of the test case and the second one the total price that is marked on the paper card under consideration of the entrance fee and minimum-consumption fee (see Sample Output below).

样例

Input
2
8
6
3 3
#############
#...#..O#..O#
#...#...#.O.#
#...#O..#O..#
#############
#...#O.O#..O#
#...#...#...#
#...#O.O#O..#
#############
#...#O.O#O.O#
#...#O.O#.O.#
#...#O.O#O.O#
#############
8
6
2 3
#########
#...#...#
#.O.#.O.#
#...#...#
#########
#...#...#
#...#.O.#
#...#...#
#########
#...#...#
#...#...#
#...#...#
#########
Output
Test case #1
price[DM]: 23
Test case #2
price[DM]: 14

1 人解决,7 人已尝试。

1 份提交通过,共有 59 份提交。

9.9 EMB 奖励。

创建: 15 年,9 月前.

修改: 6 年,8 月前.

最后提交: 3 年,5 月前.

来源: Freshman Programming Contest

题目标签