题意

有一个 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. intellij配置github

    一.在IDEA中设置Git,在File-->Setting->Version Control-->Git-->Path to Git executable选择你的git安装后的 ...

  2. java 基础 流程控制

    鄙人不才,基础不好,趁着闲时简单学习一下,仅作学习分享,如有不正确地方还请各位看客不吝指出. Java流程主要可以分为: 顺序(可以按照正常顺序一步步往下运行的) 选择(三元操作符[?:];if el ...

  3. skywalking与pinpoint全链路追踪方案对比

    由于公司目前有200多微服务,微服务之间的调用关系错综复杂,调用关系人工维护基本不可能实现,需要调研一套全链路追踪方案,初步调研之后选取了skywalking和pinpoint进行对比; 选取skyw ...

  4. 在maven项目中使用Junit进行单元测试(一)

    https://blog.csdn.net/ai_xue_xi/article/details/51819729 这篇文章相当的经典,最好使用的maven生成单元测试报告,不要在使用ant脚本生成单元 ...

  5. 05[掌握]高可用、集群、持久化、docker 等前置知识点

    高可用 24小时对外提供服务 高并发 同一时间段能处理的请求数 1,中心化和去中心化 1.1,中心化 意思是所有的节点都要有一个主节点 缺点:中心挂了,服务就挂了 中心处理数据的能力有限,不能把节点性 ...

  6. 在Github上建立自己的个人主页

    目录 注册Github账号 登录Github账号 建立新仓库 选择个人主页的主题 注册Github账号 首先打开Github的主页(https://github.com/),点击右上角的sign up ...

  7. 缺少对公共可见类型或成员的XML注释

    最近突然心血来潮,想清理下代码,结果看到了一堆这样的警告——缺少对公共可见类型或成员“XXX”的 XML 注释: 其实要想取消上面的警告,仅仅需要在项目属性里找到生成页签里的”错误和警告“项,在禁止显 ...

  8. LeetCode-Stack-Easy

    简单题 1. 有效的括号(leetcode-20) 给定一个只包括 '(',')','{','}','[',']' 的字符串,判断字符串是否有效. 有效字符串需满足: 1. 左括号必须用相同类型的右括 ...

  9. 关于gulp复制文件时把整个目录结构都复制的问题解决

    有这么个场景,在开发时分模块开发,但是发布时不一定将按模块分布,比如,为了便于开发,图片是按照模块存放的,但是发布时只是放在images文件夹下,此时就需要用到本文中提到的插件gulp-flatten ...

  10. angular入门--绑定字符串

    要使用angularjs,首先得下载并且在页面中调用它 先上源码 <html ng-app="app1"> <head> <meta name=&qu ...