我是靠谱客的博主 简单啤酒,最近开发中收集的这篇文章主要介绍B. NEW THEATRE SQUARE,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

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]='';
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;
}

最后

以上就是简单啤酒为你收集整理的B. NEW THEATRE SQUARE的全部内容,希望文章能够帮你解决B. NEW THEATRE SQUARE所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(46)

评论列表共有 0 条评论

立即
投稿
返回
顶部