B. NEW THEATRE SQUARE

52 篇文章 1 订阅

http://www.yyycode.cn/index.php/2020/05/30/b-new-theatre-square/


ou 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 rowNote 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.ExampleinputCopy

4
1 1 10 1
.
1 2 10 1
..
2 1 10 1
.
.
3 3 3 7
..*
*..
.*.

outputCopy

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.


题意:有1块白砖的钱,两块平行白砖的钱,问把能铺白色砖头的地方全铺的最小花费是多少

知识点:贪心+模拟

思路:先找出什么时候1块白砖的钱和两块平行白砖的等价。x*2==y的时候

也就是x*2<=y,那就全部都用1块白砖去铺就行了。反之能用两块的时候用两块

#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=1e5;
typedef long long LL;
char a[120][1100];
int	 vis[120][1100];
int main(void)
{
	LL t;cin>>t;
	while(t--)
	{
		LL n,m,x,y;
		cin>>n>>m>>x>>y;
		//测下只有一个的特殊例子 
		for(LL i=1;i<=n+10;i++)
		 	for(LL j=1;j<=m+10;j++)
		 	 	a[i][j]='\0';
		for(LL i=1;i<=n+10;i++)
		 	for(LL j=1;j<=m+10;j++)	 	
				vis[i][j]=0;
		for(LL i=1;i<=n;i++)
		 	for(LL j=1;j<=m;j++)
		 		cin>>a[i][j];
		LL sum=0;
		if(2*x<=y)
		{
			for(LL i=1;i<=n;i++)
		 		for(LL j=1;j<=m;j++)
					if(a[i][j]=='.')
						sum+=x;
			cout<<sum<<endl;						 
		}
		else
		{
			for(LL i=1;i<=n;i++)
		 		for(LL j=1;j<=m;j++)
		 		{
		 			if(a[i][j]=='.'&&a[i][j+1]=='.'&&vis[i][j]==0&&vis[i][j+1]==0)
					 	{
						 sum+=y;
						 vis[i][j]=1;vis[i][j+1]=1;
						}
					else if(vis[i][j]==0&&a[i][j]=='.')
					{
						sum+=x;	 vis[i][j]=1;	
					}
				}
			cout<<sum<<endl;	
		}
	}

return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值