Nanami's Digital Board
题意:
给出点(x1,y1),求以x=x1为上边界,或下边界;以y=y1为左边界,或右边界矩形的最大值(矩形内所有的点均为1)
定义四个数组lft[][],rht[][],up[][],down[][]
在up[x][y]中存的是
点(x,y)的上边有多少个连续的1
其他同理;
在确定最大的矩形时,用到了枚举法,go函数;
代码参考自:vjudge2
代码风格:思路清晰,代码明了
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
const int MAX = ;
bool ma[MAX][MAX];
int lft[MAX][MAX],rht[MAX][MAX],up[MAX][MAX],down[MAX][MAX];
int len[MAX];
int rows,cols,q; void upd_row(int x)
{
for(int j=; j<=cols; j++)
{
if(ma[x][j])
lft[x][j] = lft[x][j-]+;
else lft[x][j]=;
}
for(int j=cols; j>=; j--)
{
if(ma[x][j])
rht[x][j]=rht[x][j+]+;
else rht[x][j] =;
}
}
void upd_col(int y)
{
for(int i=; i<=rows; i++)
{
if(ma[i][y])
up[i][y] = +up[i-][y];
else up[i][y] = ;
}
for(int i=rows; i>=; i--)
{
if(ma[i][y])
down[i][y]=+down[i+][y];
else down[i][y]=;
}
} int go(int tmp,int n)
{
int leftmost = tmp;
int rightmost = tmp;
int ret = ;
for(int final = len[tmp]; final >=; final--)
{
while(leftmost>= && final<=len[leftmost])
--leftmost;
while(rightmost<=n && final<=len[rightmost])
++rightmost;
ret = max(ret,final*(rightmost-leftmost-));
}
return ret;
}
int main()
{
int i,j;
int op,x,y;
int ans;
while(scanf("%d %d %d",&rows,&cols,&q)!=EOF)
{
for(i=; i<=rows; i++)
for(j=; j<=cols; j++)
scanf("%d",&ma[i][j]);
for(i=; i<=rows; i++)
upd_row(i);
for(j=; j<=cols; j++)
upd_col(j);
while(q--)
{
scanf("%d %d %d",&op,&x,&y);
if(op==)
{
ma[x][y]=!ma[x][y];
//for(i=1; i<=rows; i++)
upd_row(x);
//for(j=1; j<=cols; j++)
upd_col(y);
}
else
{
ans=;
for(i=; i<=rows; i++)len[i]=lft[i][y];
ans=max(ans,go(x,rows));
for(i=; i<=rows; i++)len[i]=rht[i][y];
ans=max(ans,go(x,rows));
for(j=; j<=cols; j++)len[j]=down[x][j];
ans=max(ans,go(y,cols));
for(j=; j<=cols; j++)len[j]=up[x][j];
ans=max(ans,go(y,cols));
printf("%d\n",ans);
}
}
}
return ;
}
Nanami's Digital Board的更多相关文章
- codeforces 434B B. Nanami's Digital Board(分治)
题目链接: B. Nanami's Digital Board time limit per test 1 second memory limit per test 256 megabytes inp ...
- Codeforces Round #248 (Div. 1) B. Nanami's Digital Board 暴力 前缀和
B. Nanami's Digital Board 题目连接: http://www.codeforces.com/contest/434/problem/B Description Nanami i ...
- Nanami's Digital Board CodeForces - 434B (棋盘dp)
大意: 给定01矩阵, m个操作, 操作1翻转一个点, 操作2求边界包含给定点的最大全1子矩阵 暴力枚举矩形高度, 双指针统计答案 #include <iostream> #include ...
- Codeforces Round #248 (Div. 1)——Nanami's Digital Board
题目连接 题意: 给n*m的0/1矩阵,q次操作,每次有两种:1)将x,y位置值翻转 2)计算以(x,y)为边界的矩形的面积最大值 (1 ≤ n, m, q ≤ 1000) 分析: 考虑以(x,y)为 ...
- codeforces248(div1) B Nanami's Digital Board
q次询问,每次询问能够对矩阵某一个值改变(0变1.1变0) 或者是查询子矩阵的最大面积,要求这个这个点在所求子矩阵的边界上,且子矩阵各店中全为1 用up[i][j]表示(i,j)这个点向上能走到的最长 ...
- Codeforces Round #248 (Div. 2) (ABCD解决问题的方法)
比赛链接:http://codeforces.com/contest/433 A. Kitahara Haruki's Gift time limit per test:1 second memory ...
- The STM32F746G-DISCO discovery board -- MBED
https://developer.mbed.org/platforms/ST-Discovery-F746NG/ Microcontroller features STM32F46NGH6 in T ...
- Digital Adjustment of DC-DC Converter Output Voltage in Portable Applications
http://pdfserv.maximintegrated.com/en/an/AN818.pdf http://www.maximintegrated.com/app-notes/index.mv ...
- POJ 1691 Painting a Board(状态压缩DP)
Description The CE digital company has built an Automatic Painting Machine (APM) to paint a flat boa ...
随机推荐
- python加密之hashlib
1.强大的hashlib,提供了用于加密相关的操作,代替了md5模块和sha模块,主要提供 SHA1, SHA224, SHA256, SHA384, SHA512 ,MD5 算法 2.hmac模块实 ...
- Fragment和FragmentActivity的使用
可以分为下面的几部分: 使用支持库 创建一个Fragment 创建一个动态UI 多个Fragment之间的通信 1.使用支持库 如果您的应用需要运行在3.0及以上的版本,可以忽略这部分内容. 如果您的 ...
- 读取zip文件,不解压缩直接解析,支持文件名中文,解决内容乱码
使用ant.jar进行文件zip压缩 import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import j ...
- shell变量(字符串)间的连接
shell变量(字符串)间的连接 对于变量或者字符串的连接,shell提供了相当简单的做法,比string的连接还要直接. 直接放到一起或用双引号即可. 例如$a, $b,有 c=$a$b c=$a& ...
- [转载]amba_device使用分析
什么是AMBA? ---AMBA是一个片内总线规范. ARM官网的介绍:http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0 ...
- JDK 8 - Lambda Expression 的优点与限制
我们知道 JDK 8 新增了 Lambda Expression 这一特性. JDK 8 为什么要新增这个特性呢? 这个特性给 JDK 8 带来了什么好处? 它可以做什么?不可以做什么? 在这篇文章, ...
- 安装appium需要注意的事项
参考 虫师 的博客园 :http://www.cnblogs.com/fnng/p/4560298.html 1.其中第二篇中,打开命令行用的不是windows中的cmd打开的界面,而是用node. ...
- 根据MAC地址前6位知道网络设备是哪家公司生产的
http://standards-oui.ieee.org/oui/oui.txt https://files.cnblogs.com/files/itfat/oui.rar
- python开发模块基础:序列化模块json,pickle,shelve
一,为什么要序列化 # 将原本的字典.列表等内容转换成一个字符串的过程就叫做序列化'''比如,我们在python代码中计算的一个数据需要给另外一段程序使用,那我们怎么给?现在我们能想到的方法就是存在文 ...
- C++11 类的六个默认函数及其使用
六个默认函数: 构造函数(construct) 析构函数(destruct) 复制构造函数(copy construct) 赋值(assign) 移动构造函数(move construct) 移动赋值 ...