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 ...
随机推荐
- 何凯文每日一句打卡||DAY1~DAY3
01长难句 In an open meeting with congressional Democrats and Republicans, Trump embraced raising the ag ...
- windows下自动启动Redis隐藏命令行窗口
这段时间看了看关于Redis的相关内容,对于Redis在windows下的安装和常规启动我就不多说了.可以参考其他的博客http://www.cnblogs.com/edisonchou/p/3821 ...
- 图片src拼接后台返回ID
本文地址:http://www.cnblogs.com/veinyin/p/8507403.html 在学习 CSS 时只了解了给固定地址,但是如果给的是一个需要拼接的地址就蒙了,以下是基于 Vue ...
- 让PHPCms内容页支持JavaScript的修改方法
在文件..\caches\caches_model\caches_data\content_input.class.php中找到函数: function get($data,$isimport = 0 ...
- 16、DecimalFormat类
DecimalFormat类概述 在一些金融或者银行的业务里面,会出现这样千分位格式的数字,¥123,456.00,表示人民币壹拾贰万叁仟肆佰伍拾陆元整,java.text包下提供了一个Decimal ...
- javascript 中的类数组和数组
什么是类数组呢? 我们先来看一段代码: function fn() { console.dir(arguments); } fn(1,2,3,4,5,6,7,8,9,10); 这段代码的执行后,在 c ...
- 差分约束系统+输出路径(I - Advertisement POJ - 1752 )
题目链接:https://cn.vjudge.net/contest/276233#problem/I 题目大意:输入k和n,然后输入n行,每一次输入两个数,代表开端和结尾,如果这个区间内点的个数大于 ...
- 2016.5.18——Excel Sheet Column Number
Excel Sheet Column Number 本题收获: 1.对于字符串中字母转为ASIIC码:string s ;res = s[i]-'A'; 这个res就是数字s[i]-'A'是对ASII ...
- 渗透测试的WINDOWS NTFS技巧集合
译者:zzzhhh 这篇文章是来自SEC Consult Vulnerability Lab的ReneFreingruber (@ReneFreingruber),分享了过去几年从各种博客文章中收集的 ...
- Mysql中truncate table和delete语句的区别
Mysql中的truncate table和delete语句都可以删除表里面所有数据,但是在一些情况下有些不同! 例子: truncate table gag; (1)truncate table删除 ...