B. New Theatre Square难度 1000 / 贪心 模拟

Posted 幽殇默

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了B. New Theatre Square难度 1000 / 贪心 模拟相关的知识,希望对你有一定的参考价值。


https://codeforces.com/problemset/problem/1359/B

#include<bits/stdc++.h>
using namespace std;
char a[110][1100];
int main(void)
{
	int t; cin>>t;
	while(t--)
	{
		int n,m,x,y; cin>>n>>m>>x>>y;
		int ans=0;
		for(int i=0;i<n;i++)
		{
			int cnt=0;
			for(int j=0;j<m;j++)
			{
				cin>>a[i][j];
				if(a[i][j]=='.') cnt++;
				else 
				{
					if(cnt>=2)
					{
						if(y<2*x) ans+=cnt/2*y+(cnt%2)*x;//看哪个更优 
						else ans+=cnt*x;
					}
					else ans+=cnt*x;
					cnt=0;
				}
			}
			if(cnt)//如果结束还有统计 
			{
				if(cnt>=2)
				{
					if(y<2*x) ans+=(cnt/2)*y+(cnt%2)*x;//二块砖更优 
					else ans+=cnt*x;
				}
				else ans+=cnt*x;
				cnt=0;
			}
		}
		cout<<ans<<endl;
	}
}

以上是关于B. New Theatre Square难度 1000 / 贪心 模拟的主要内容,如果未能解决你的问题,请参考以下文章

Educational Codeforces Round 88 (Rated for Div. 2) B. New Theatre Square

题解 CF1359B New Theatre Square

题解 CF1359B New Theatre Square

Codeforces Beta Round #1 A. Theatre Square 题解

codeforces 1 A题 : Theatre Square(水)

Codeforces 1A Theatre Square