题意

有一个 n×m 的广场,其中一部分要铺地砖,地砖有两种, 1 × 1 和 1×2 的,后者只能横着铺,其中, 1 × 1的单价为 x , 1 × 2 的单价为 y , 输入这个广场,"."表示要铺地砖,求最少花费。注意,地砖不可重合,也不可覆盖在已铺地砖区域。

思路

这显然是贪心,分别计算全铺 $ 1 × 1$ 的方案价钱和尽量多铺 $ 1 × 2$ 的方案价钱,最后将最小的输出,因为只能横铺,方向固定,所以十分简单。

代码

具体细节见注释

#include<bits/stdc++.h>
#define _for(i,a,b) for(int i=(a);i<(b);i++)
#define _rep(i,a,b) for(int i=(a);i<=(b);i++)
#define floor Fl //好像floor是关键字?于是我宏定义了一下
#define lol long long
#define re read()
using namespace std;
const int MAXN=1e3+10;
int read(){
#define ge getchar()
int x=0,sgn=1;char ch=ge;
for(;!isdigit(ch);ch=ge)if(ch=='-')sgn=-1;
for(;isdigit(ch);ch=ge)x=(x<<1)+(x<<3)+(ch^48);
return x*sgn;
}
int T,n,m,x,y;
int floor[MAXN][MAXN];
int main (){
T=re;
while(T--){
n=re;m=re;x=re;y=re;int tot1=0,tot2=0;
_rep(i,1,n){
_rep(j,1,m){
char ch=ge;
while(ch!='.'&&ch!='*')ch=ge;
if(ch=='.'){
floor[i][j]=1;
tot1++;
//tot1表示除了被铺1*2的,可铺多少1*1的地砖
if(floor[i][j-1]&&floor[i][j])floor[i][j-1]=0,floor[i][j]=0,tot1-=2,tot2++;
//tot2表示可以最多铺多少1*2 的地砖
}
else floor[i][j]=0;
}
}
lol ans1=tot1*x+tot2*y,ans2=tot1*x+tot2*2*x;
//计算方案,lol:long long
printf("%lld\n",min(ans1,ans2));
}
return 0;
}

题解 CF1359B 【New Theatre Square】的更多相关文章

  1. Educational Codeforces Round 88 (Rated for Div. 2) B、New Theatre Square C、Mixing Water

    题目链接:B.New Theatre Square 题意: 你要把所有"." 都变成"*",你可以有两个选择,第一种就是一次铺一个方块(1*1),第二种就是同一 ...

  2. cf--------(div1)1A. Theatre Square

    A. Theatre Square time limit per test 2 seconds memory limit per test 64 megabytes input standard in ...

  3. Theatre Square

    http://codeforces.com/problemset/problem/1/A Theatre Square time limit per test 2 seconds memory lim ...

  4. CF Theatre Square

    Theatre Square time limit per test 2 seconds memory limit per test 64 megabytes input standard input ...

  5. codeforce 1A Theatre Square

    A. Theatre Square Theatre Square in the capital city of Berland has a rectangular shape with the siz ...

  6. CodeForces 1A Theatre Square

    A - Theatre Square Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u ...

  7. A. Theatre Square(math)

    A. Theatre Square time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  8. LeetCode题解:(221) Maximal Square

    题目说明 Given a 2D binary matrix filled with 0's and 1's, find the largest square containing only 1's a ...

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

    题目链接:https://codeforces.com/contest/1359/problem/B 题意 有一块 $n \times m$ 的地板和两种瓷砖: $1 \times 1$,每块花费为 ...

随机推荐

  1. 13.DRF-版本

    Django rest framework源码分析(4)----版本 版本 新建一个工程Myproject和一个app名为api (1)api/models.py from django.db imp ...

  2. Linux Pam后门总结拓展

    首发先知社区: https://xz.aliyun.com/t/7902 前言 渐渐发现pam后门在实战中存在种植繁琐.隐蔽性不强等缺点,这里记录下学习pam后门相关知识和pam后门的拓展改进. 0x ...

  3. Python-16-分配参数

    与收集参数相反,这里用*和**分配参数   def add(x, y):          return x + y   使用*分配元组 params = (1, 2) >>> ad ...

  4. eclipse .project文件 .classpath文件的作用

    .classpath文件的作用 可以参考.classpath文件的作用 .project文件的作用 确保你自己的eclipse能创建Java项目,并且正确编译运行helloworld,给eclipse ...

  5. URL is not registered (Settings | Languages & Frameworks | Schemas and DTDs)

    File - Settings - Schemas and DTDS时,选中报错的地址,然后Ctrl+alt+s打开设置(或者右键 -> setting)找到 把报错的地址填入就可以了,最后应用 ...

  6. 【服务器】CentOs7系统使用宝塔面板搭建网站,有FTP配置(保姆式教程)

    内容繁多,请耐心跟着流程走,在过程中遇到问题请在下面留言(我只是小白,请专业人士喷轻点). 这次用thinkphp5.1做演示,单纯的做演示,我打算下一篇文章用typecho(博客框架)演示. 前言 ...

  7. python实现将大文件夹分割成多个子文件夹

    楼主用的linux,一旦数据达到几万,文件夹打开就会变卡,同时也方便同时分工协作,便于git管理,写了个将大文件夹分割成多个小文件夹的脚本 如操作文件夹:img,脚本不破坏img的数据,创建img_1 ...

  8. js基础练习题(6)

    10.其他 1.选择题 var name = 'World!'; (function () { if (typeof name === 'undefined') { var name = 'Nodei ...

  9. (私人收藏)React教程手册

    React教程手册 https://pan.baidu.com/s/1ka2PJ54HgqJ8lC6XgbvdLg pedx React 教程 含有3个附件,如下: react.js react-do ...

  10. java语言进阶(五)_异常

    第一章 异常 1.1 异常概念 异常 :指的是程序在执行过程中,出现的非正常的情况,最终会导致JVM的非正常停止. 在Java等面向对象的编程语言中,异常本身是一个类,产生异常就是创建异常对象并抛出了 ...