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 ...
随机推荐
- 完美配置Python3.5+Anaconda+PyQt5,实现UI和其他模块的结合
sklearn实战-乳腺癌细胞数据挖掘(博主亲自录制视频) https://study.163.com/course/introduction.htm?courseId=1005269003& ...
- [Java] I/O底层原理之一:字符流、字节流及其源码分析
关于 I/O 的类可以分为四种: 关于字节的操作:InputStream 和 OutPutStream: 关于字符的操作:Writer 和 Reader: 关于磁盘的操作:File: 关于网络的操作: ...
- C/C++中的回调函数
在理解“回调函数”之前,首先讨论下函数指针的概念. 函数指针 (1)概念:指针是一个变量,是用来指向内存地址的.一个程序运行时,所有和运行相关的物件都是需要加载到内存中,这就决定了程序运行时的任何物件 ...
- Linux下查看系统版本和make版本
一.查看Linux内核版本命令(两种方法): 1.cat /proc/versionz [root@localhost ~]# cat /proc/versionLinux version 2.6.1 ...
- MinGW安装设置
From:http://www.cnblogs.com/killerlegend/p/3746504.html Author:KillerLegend Date:2014.5.22 不得不吐槽一下学校 ...
- [转载]mysql下载安装
转自https://www.cnblogs.com/tyhj-zxp/p/6693046.html 下载 打开:https://www.mysql.com/downloads/ 1.点击该项:
- Postman简明教程
一.Postman简介 Postman是一款接口测试工具,常用于日常工作的接口类功能测试和简单的自动化测试. 二.Postman功能介绍 1.常见get请求的接口测试 我们现在有这样一个获取学生信息的 ...
- Elasticsearch技术解析与实战(一)基础概念及环境搭建
序言 ES数据架构的主要概念(与关系数据库Mysql对比) 集群(cluster) 集群,一个ES集群由一个或多个节点(Node)组成,每个集群都有一个cluster name作为标识.一下是我们的4 ...
- 实现asp.net的文件压缩、解压、下载
很早前就想做文件的解压.压缩.下载 了,不过一直没时间,现在项目做完了,今天弄了下.不过解压,压缩的方法还是看的网上的,嘻嘻~~不过我把它们综合了一下哦.呵呵~~ 1.先要从网上下载一个icsharp ...
- Java 图片转字节流 实现 图片->字节流(字符串)->图片
//该方法实现图片转String 参数为图片的路径 可以是file.toString()得到public String testUpload(String path) { try { String s ...