概述
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
You might have remembered Theatre square from the problem 1A. Now it's finally getting repaved.
The square still has a rectangular shape of n×mn×m meters. However, the picture is about to get more complicated now. Let ai,jai,j be the jj-th square in the ii-th row of the pavement.
You are given the picture of the squares:
- if ai,j=ai,j= "*", then the jj-th square in the ii-th row should be black;
- if ai,j=ai,j= ".", then the jj-th square in the ii-th row should be white.
The black squares are paved already. You have to pave the white squares. There are two options for pavement tiles:
- 1×11×1 tiles — each tile costs xx burles and covers exactly 11 square;
- 1×21×2 tiles — each tile costs yy burles and covers exactly 22 adjacent squares of the same row. Note that you are not allowed to rotate these tiles or cut them into 1×11×1 tiles.
You should cover all the white squares, no two tiles should overlap and no black squares should be covered by tiles.
What is the smallest total price of the tiles needed to cover all the white squares?
Input
The first line contains a single integer tt (1≤t≤5001≤t≤500) — the number of testcases. Then the description of tt testcases follow.
The first line of each testcase contains four integers nn, mm, xx and yy (1≤n≤1001≤n≤100; 1≤m≤10001≤m≤1000; 1≤x,y≤10001≤x,y≤1000) — the size of the Theatre square, the price of the 1×11×1 tile and the price of the 1×21×2 tile.
Each of the next nn lines contains mm characters. The jj-th character in the ii-th line is ai,jai,j. If ai,j=ai,j= "*", then the jj-th square in the ii-th row should be black, and if ai,j=ai,j= ".", then the jj-th square in the ii-th row should be white.
It's guaranteed that the sum of n×mn×m over all testcases doesn't exceed 105105.
Output
For each testcase print a single integer — the smallest total price of the tiles needed to cover all the white squares in burles.
Example
input
Copy
4 1 1 10 1 . 1 2 10 1 .. 2 1 10 1 . . 3 3 3 7 ..* *.. .*.
output
Copy
10 1 20 18
Note
In the first testcase you are required to use a single 1×11×1 tile, even though 1×21×2 tile is cheaper. So the total price is 1010 burles.
In the second testcase you can either use two 1×11×1 tiles and spend 2020 burles or use a single 1×21×2 tile and spend 11 burle. The second option is cheaper, thus the answer is 11.
The third testcase shows that you can't rotate 1×21×2 tiles. You still have to use two 1×11×1 tiles for the total price of 2020.
In the fourth testcase the cheapest way is to use 1×11×1 tiles everywhere. The total cost is 6⋅3=186⋅3=18.
解题说明:此题是一道模拟题,对矩形进行遍历,判断费用时需要进行比较哪种划算。
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int t, r, c, i, j, k, p, s, x, y;
scanf("%d", &t);
while (t--)
{
scanf("%d %d %d %d", &r, &c, &x, &y);
char n[101][1001];
for (i = 0; i < r; i++)
{
scanf("%s", n[i]);
}
s = 0;
for (i = 0; i<r; i++)
{
for (j = 0; j<c; j++)
{
if (n[i][j] == '.')
{
if (j<c - 1 && n[i][j + 1] == '.')
{
if (x * 2 > y)
{
s = s + y;
j++;
}
else
{
s = s + (x * 2);
j++;
}
}
else
{
s = s + x;
}
}
}
}
printf("%dn", s);
}
return 0;
}
最后
以上就是妩媚微笑为你收集整理的B. New Theatre Square的全部内容,希望文章能够帮你解决B. New Theatre Square所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复