博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces Round #423 B. Black Square
阅读量:4990 次
发布时间:2019-06-12

本文共 1703 字,大约阅读时间需要 5 分钟。

题目网址:http://codeforces.com/contest/828/problem/B

题目:

Polycarp has a checkered sheet of paper of size n × m. Polycarp painted some of cells with black, the others remained white. Inspired by Malevich's "Black Square", Polycarp wants to paint minimum possible number of white cells with black so that all black cells form a square.

You are to determine the minimum possible number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. The square's side should have positive length.

Input

The first line contains two integers n and m (1 ≤ n, m ≤ 100) — the sizes of the sheet.

The next n lines contain m letters 'B' or 'W' each — the description of initial cells' colors. If a letter is 'B', then the corresponding cell is painted black, otherwise it is painted white.

Output

Print the minimum number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. If it is impossible, print -1.

Examples
input
5 4 WWWW WWWB WWWB WWBB WWWW
output
5
input
1 2 BB
output
-1
input
3 3 WWW WWW WWW
output
1 以第一个例子为例:
代码:
1 #include 
2 #include
3 using namespace std; 4 const int INF=1111111; 5 int n,m; 6 int u,d,l,r;//上下左右取值 7 int a,b;//长宽 8 int num;//原始黑细胞数量 9 int len;//正方形边长10 char square[105][105];11 void init(){12 u=l=INF;13 d=r=-INF;14 num=0;15 }16 int main(){17 init();18 scanf("%d%d ",&n,&m);19 for (int i=0; i

 

 

转载于:https://www.cnblogs.com/uniles/p/7156033.html

你可能感兴趣的文章
递归C++
查看>>
POJ 1751 Highways(最小生成树&Prim)题解
查看>>
linux 安装openssh-server, openssh-client
查看>>
Java继承的基本概念及其限制 总结
查看>>
RF1001: 各浏览器对 '@font-face' 规则支持的字体格式不同,IE 支持 EOT 字体,Firefox Safari Opera 支持 TrueType 等字体...
查看>>
Socket 学习(三)
查看>>
题解 CF43B 【Letter】
查看>>
CommandName and CommandArgument
查看>>
[z]FNV哈希算法
查看>>
通过层序和中序遍历序列重建二叉树
查看>>
【Git】git clone与git pull区别
查看>>
【SVN】SVN的trunk、branches、tag的使用以及分支的概念
查看>>
JS闭包理解
查看>>
整数对题目
查看>>
php设计模式-观察者模式
查看>>
NFC技术:使用Android Beam技术传输文本(一)
查看>>
C++判断一个文件是否可以正确打开的代码
查看>>
unity 判断 是手机还是平板
查看>>
VisualStudio2015单步调试
查看>>
【进程资源】监视进程资源
查看>>