New Theatre Square
https://codeforces.com/problemset/problem/1359/B
思路:可以用bfs搜索每一个连通块,得到每一个连通块的 . 的数量,然后我们再判断是贴一块划算还是贴两块划算,然后这里要注意一下两块的瓷砖只能贴同一行的两个
以下是代码实现:
#include<iostream>
#include<queue>
using namespace std;char board[110][1010];
int n,m,x,y;
int ny[2]={1,-1};
int nx[2]={0,0};
struct node
{int x,y;
};
int bfs(int X,int Y)
{int cnt=1;board[X][Y]='*';queue<node>q;node start,next;start.x=X,start.y=Y;q.push(start);while(!q.empty()){start=q.front();q.pop();for(int i=0;i<2;i++){int dx=start.x+nx[i];int dy=start.y+ny[i];if(1<=dx&&dx<=n&&1<=dy&&dy<=m&&board[dx][dy]=='.')//只能是同一行{board[dx][dy]='*';next.x=dx,next.y=dy;q.push(next);cnt++;}}}return cnt;
}
void solved()
{cin>>n>>m>>x>>y;int sum=0;for(int i=1;i<=n;i++){for(int j=1;j<=m;j++){cin>>board[i][j];}}for(int i=1;i<=n;i++){for(int j=1;j<=m;j++){if(board[i][j]=='.'){int cnt=bfs(i,j);if((y/2)<x){sum+=(cnt/2)*y+(cnt%2)*x;}else sum+=cnt*x;}}}cout<<sum<<endl;return ;
}
int main()
{ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);int t;cin>>t;while(t--){solved();}return 0;
}
New Theatre Square相关推荐
- CF Theatre Square
Theatre Square time limit per test 2 seconds memory limit per test 64 megabytes input standard input ...
- Theatre Square
time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...
- 【CodeForces - 1A】Theatre Square(水题,几何)(CODEFORCES,梦的开始)
题干: Theatre Square in the capital city of Berland has a rectangular shape with the size n × m meters ...
- CodeForces-1A Theatre Square【水题】
A. Theatre Square time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- CodeForces 1A Theatre Square(水题)
A. Theatre Square time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- CodeForces刷题:Theatre Square、Watermelon、Chat Server‘s Outgoing Traffic、Triangle、Die Roll
记录Codeforces刷题QAQ 一.Theatre Square 题面翻译 用 $ a \times a$ 的石板覆盖 $n \times m $ 的长方形广场,允许石板覆盖的区域超出广场,不允许 ...
- cf 1A Theatre Square
在刷完十多道CF A,B题水题后 ,便迫不及待的开始写下我的第一篇博客,以此来纪念我ACM的开始 . 纯小白,代码有很多不足之处,希望大家指教.也希望我的解题报告可以对大家有那么一点点的帮助. 1,C ...
- 1A. Theatre Square
1A. Theatre Square 题目 翻译 题目 输入 输出 分析 代码 题目 翻译 题目 首都柏林的剧院广场是一个n×m 的矩形.在城市周年纪念之际,决定用方形的花岗岩石板铺砌广场,每个石板大 ...
- E - Theatre Square
E - Theatre Square 一个城市的广场面积有 N×M平方米,过段时间,恰逢这个城市的庆典活动,主办方决定在广场上铺设一种新的地砖,这种地砖每块都是a×a平方米的. 那么问题来了,最少需要 ...
最新文章
- Postman(使用指南)
- ecmall支持php5.3,在PHP5.3以上版本运行ecshop和ecmall出现的问题及解决方案
- 51 NOD 1363 最小公倍数之和 (欧拉函数思维应用)
- 【渝粤教育】国家开放大学2018年春季 0062-21T港台文学专题讲座 参考试题
- Netty 服务 接收新数据
- java字节型的关键字_DAY06-07 Java的基础语法-注释、标识符、关键字、数据类型
- python的数据库操作_Python对数据库操作
- 关于jQuery、AJAX、JSON(一)
- 线切割计算机传输出错,为什么线切割单板机总传不了或出错?解开传送数据之迷...
- [ProblemSolving]ut下载磁盘负荷过重
- Java家庭收支记账程序
- Android TextView更换字体
- 用计算机求方差的教案,《用科学计算器计算方差》教案.doc
- python3精简笔记(三)——高级特性
- 风险准备(金)这样(估)算,来年工作不白干
- Firefox 扩展插件
- Java中的byte[]/char[]/int/String数据类型转换
- java判断两个数互质_AcWing 458. 比例简化-java(无需判断互质)
- 21 、查询不同老师所教不同课程平均分从高到低显示(不重点)(自己做出)
- windows rabbit mq启动失败