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 ...
随机推荐
- C#网络编程(接收文件) - Part.5
这篇文章将完成 Part.4 中剩余的部分,它们本来是一篇完整的文章,但是因为上一篇比较长,合并起来页数太多,浏览起来可能会比较不方便,我就将它拆为两篇了,本文便是它的后半部分.我们继续进行上一篇没有 ...
- 洛谷 1155 (NOIp2008)双栈排序——仔细分析不合法的条件
题目:https://www.luogu.org/problemnew/show/P1155 这道题教会我们要多思考. 好好分析过后发现同一个栈里不能有升序.就用它写了一个30分. #include& ...
- 导出csv xls文件数字会自动变科学计数法的解决方式
将数据导出excel文件变成科学计数法问题: 分析: 用程序导出的csv文件,当字段中有比较长的数字字段存在时,在用excel软件查看csv文件时就会变成科学技术法的表现形式. 其实这个 ...
- FPGA前世今生(二)
上期我们介绍了关于FPGA内部最基本的结构,在quartus下可以看到整体的结构. 这是在平面规划图下看到的结构,其中蓝色的小格代表一个LAB.四周边上浅棕色的小格代表IO口. 这是一个LAB的内部结 ...
- MinGW下载并配置gcc/g++编译环境
本文将讲解如何下载MinGW并配置gcc\g++编译环境 一.下载MinGW 在MinGW官网中下载“mingw-get-setup.exe” 官网传送门:http://www.mingw.org/ ...
- Quartz.net 2.x 学习笔记01
Quartz.net 2.0 2012年4月9日发布了Released版本,到目前(2014-12-08)为止是2.3版 Quartz.net 项目地址:http://www.quartz-sched ...
- 解决git gnutls_handshake失败
sudo apt-get install build-essential fakeroot dpkg-dev mkdir ~/git-openssl cd ~/git-openssl sudo apt ...
- 4.solr学习速成之bean
以bean的形式提交索引,以bean的形式查询出来 package com.liucheng.solr; import java.io.Serializable; import org.apache. ...
- 如何查看路由器中的pppoe拨号密码?
1 2 3 4 5 6 分步阅读 有时候把宽带的账号密码给忘了,进路由器的拨号页面看了一下,账号能看到,就密码是以“*”号形式显示的,没法用“肉眼”识别出来,怎么办呢?难道真的非得打电话问运营商不可? ...
- DIV+CSS+JS实现图片<ul><li></li></ul>无缝滚动代码
(含上下左右滚动代码) <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:/ ...