CF475C. Kamal-ol-molk's Painting
2 seconds
256 megabytes
standard input
standard output
Rumors say that one of Kamal-ol-molk's paintings has been altered. A rectangular brush has been moved right and down on the painting.
Consider the painting as a n × m rectangular grid. At the beginning an x × y rectangular brush is placed somewhere in the frame, with edges parallel to the frame, (1 ≤ x ≤ n, 1 ≤ y ≤ m). Then the brush is moved several times. Each time the brush is moved one unit right or down. The brush has been strictly inside the frame during the painting. The brush alters every cell it has covered at some moment.
You have found one of the old Kamal-ol-molk's paintings. You want to know if it's possible that it has been altered in described manner. If yes, you also want to know minimum possible area of the brush.
The first line of input contains two integers n and m, (1 ≤ n, m ≤ 1000), denoting the height and width of the painting.
The next n lines contain the painting. Each line has m characters. Character 'X' denotes an altered cell, otherwise it's showed by '.'. There will be at least one altered cell in the painting.
Print the minimum area of the brush in a line, if the painting is possibly altered, otherwise print - 1.
4 4
XX..
XX..
XXXX
XXXX
4
4 4
....
.XXX
.XXX
....
2
4 5
XXXX.
XXXX.
.XX..
.XX..
-1
模拟即可,水题玩玩。代码能力略渣啊。。
#include <bits/stdc++.h>
using namespace std;
const int maxn = + ;
char g[maxn][maxn];
int n, m, minX, minY, ans;
int sum[maxn][maxn], cnt, tot;
int getSum(int a, int b, int x, int y) {
return sum[a][b] - sum[a][y + ] - sum[x + ][b] + sum[x + ][y + ];
}
bool ok(int a, int b, int posX = minX, int posY = minY) {
while() {
if(posX + a - > n || posY + b - > m) return false;
if(getSum(posX, posY, posX + a - , posY + b - ) != a * b) return false;
if(getSum(posX, posY, n, m) == a * b && getSum(posX, posY, posX + a - , posY + b - ) == a * b) {
return (cnt + a * b == tot) ;
}
bool flag1 = (a * b) == getSum(posX + , posY, posX + a, posY + b - );
bool flag2 = (a * b) == getSum(posX, posY + , posX + a - , posY + b);
if(!flag1 && !flag2) return false;
if(flag1 && flag2) return false;
if(flag1) ++posX, cnt += b;
else ++posY, cnt += a;
}
} int main() {
scanf("%d%d", &n, &m);
for(int i = ; i <= n; ++i) {
scanf("%s", g[i] + );
}
minX = n + , minY = m + ;
ans = n * m + ;
for(int i = n; < i; --i) {
for(int j = m; < j; --j) {
sum[i][j] = sum[i][j] - sum[i + ][j + ] + sum[i + ][j] + sum[i][j + ] + (g[i][j] == 'X');
if(g[i][j] == 'X') {
minX = min(i, minX), minY = min(j, minY);
++tot;
}
}
}
for(int i = ; i <= n; ++i) {
for(int j = ; j <= m; ++j) {
if(ans <= i * j) continue;
cnt = ;
if(ok(i, j)) ans = i * j;
}
}
printf("%d\n", ans == n * m + ? - : ans); return ;
}

CF475C. Kamal-ol-molk's Painting的更多相关文章
- OpenLayers 3 之 地图样式(ol.style)详解
地图样式是由 style 类控制的,其包含了地图样式的方方面面,例如,填充色.图标样式.图片样式.规则图形样式.边界样式.文字样式等,样式一般针对矢量要素图层. 矢量图层样式可以事先写好,写成静态的, ...
- ul ol di三者区别
1.ul是无序列表,也就是说没有排列限制可以随意加li: <ul> <li>可以随意放置</li> <li>可以随意放置</li> < ...
- HTML 列表 <ol><ul><li><dl><dt><dd>
<ol>标签-有序列表 定义和用法: <ol>标签定义有序列表. HTML 与 XHTML 之间的差异 在 HTML 4.01 中,ol 元素的 "compact&q ...
- 语义化HTML:ul、ol和dl
一.语义化元素 1. ul标签 W3C草案: The ul element represents an unordered list of items; that is, a list in wh ...
- CF448C Painting Fence (分治递归)
Codeforces Round #256 (Div. 2) C C. Painting Fence time limit per test 1 second memory limit per tes ...
- HTML5 – 3.加强版ol
<ol> 标签定义了一个有序列表. 列表排序以数字来显示. 使用<li> 标签来定义列表选项. 提示和注释 提示: 如果需要无序列表,请使用 <ul> 标签. 提示 ...
- ol新属性
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- [译]使用Continuous painting mode来分析页面的绘制状态
Chrome Canary(Chrome “金丝雀版本”)目前已经支持Continuous painting mode,用于分析页面性能.这篇文章将会介绍怎么才能页面在绘制过程中找到问题和怎么利用这个 ...
- Codeforces Round #353 (Div. 2)Restoring Painting
Vasya works as a watchman in the gallery. Unfortunately, one of the most expensive paintings was sto ...
随机推荐
- NO.4day LINUX centos 文件基本操作
LINUX centos 文件基本操作 1 LINUX简介 Linux的定义:Linux是一套免费使用和自由传播的类Unix操作系统,是一个基于POSIX和UNIX的多用户.多任务.支持多线程和多CP ...
- Hadoop基础-HDFS数据清理过程之校验过程代码分析
Hadoop基础-HDFS数据清理过程之校验过程代码分析 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 想称为一名高级大数据开发工程师,不但需要了解hadoop内部的运行机制,还需 ...
- day15 接口与异常
接口 是一种独立于类的新机制,它关注的是行为. 接口的意义就体现在——让没有继承关系的类共享这些行为,各有各的具体实现. 设计上:当我们发现一个或多个类的方法相同,又没有继承关系,则考虑接口. 命名: ...
- Kafka 0.8 Controller设计机制和状态变化
在kafka集群中,其中一个broker server作为中央控制器Control,负责管理分区和副本状态并执行管理着这些分区的重新分配. 下面说明如何通过中央控制器操作分区和副本的状态. 名词解释 ...
- Shell记录-Shell脚本基础(二)
Shell 基本运算符 算术运算符: 运算符 描述 例子 + Addition - Adds values on either side of the operator `expr $a + $b` ...
- 设置PyCharm中的Python代码模版
再MacOs运行的PyCharm中,执行python文件,如果不指定python文件字符编码会报错: SyntaxError: Non-ASCII character , but no encodin ...
- NOIP2012 提高组 Day 1
期望得分:100+100+70=270 实际得分:100+50+70=220 T2 没有底 最后剩余时间来不及打高精.思路出现错误 T1 Vigenère 密码 题目描述 16 世纪法国外交家 Bla ...
- sql 存储时空格转成问号问题
最近做系统,从邮件中导出邮件,上传到系统中,遇到一个奇葩的问题,如下: 通过本地文件看,文件名中是一个空格,上传至数据库后,展示就变成了问号,究其原因,发现是一个特殊字符导致: 最近认真去查了一下这个 ...
- eclipse初始设置
1.界面显示设置 2.快捷创建的设置 window->Customize Perspective->Shortcuts 3.修改编码为utf-8 Preferences->Gener ...
- Spark1.3.1 On Yarn的集群搭建
下面给出的是spark集群搭建的环境: 操作系统:最小安装的CentOS 7(下载地址) Yarn对应的hadoop版本号:Hadoop的Cloudera公司发行版Hadoop2.6.0-CDH5.4 ...