题意:

  给出点(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的更多相关文章

  1. 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 ...

  2. 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 ...

  3. Nanami's Digital Board CodeForces - 434B (棋盘dp)

    大意: 给定01矩阵, m个操作, 操作1翻转一个点, 操作2求边界包含给定点的最大全1子矩阵 暴力枚举矩形高度, 双指针统计答案 #include <iostream> #include ...

  4. Codeforces Round #248 (Div. 1)——Nanami&#39;s Digital Board

    题目连接 题意: 给n*m的0/1矩阵,q次操作,每次有两种:1)将x,y位置值翻转 2)计算以(x,y)为边界的矩形的面积最大值 (1 ≤ n, m, q ≤ 1000) 分析: 考虑以(x,y)为 ...

  5. codeforces248(div1) B Nanami&#39;s Digital Board

    q次询问,每次询问能够对矩阵某一个值改变(0变1.1变0) 或者是查询子矩阵的最大面积,要求这个这个点在所求子矩阵的边界上,且子矩阵各店中全为1 用up[i][j]表示(i,j)这个点向上能走到的最长 ...

  6. Codeforces Round #248 (Div. 2) (ABCD解决问题的方法)

    比赛链接:http://codeforces.com/contest/433 A. Kitahara Haruki's Gift time limit per test:1 second memory ...

  7. The STM32F746G-DISCO discovery board -- MBED

    https://developer.mbed.org/platforms/ST-Discovery-F746NG/ Microcontroller features STM32F46NGH6 in T ...

  8. 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 ...

  9. POJ 1691 Painting a Board(状态压缩DP)

    Description The CE digital company has built an Automatic Painting Machine (APM) to paint a flat boa ...

随机推荐

  1. npm 私服工具verdaccio 安装配置试用

      1. 安装 npm install -g verdaccio 2. 启动 verdaccio // 界面显示信息 Verdaccio doesn't need superuser privileg ...

  2. 【转】简单明了区分escape、encodeURI和encodeURIComponent

    一.前言 讲这3个方法区别的文章太多了,但是大部分写的都很绕.本文试图从实践角度去讲这3个方法. 二.escape和它们不是同一类 简单来说,escape是对字符串(string)进行编码(而另外两种 ...

  3. Python 函数 set()

    set() 功能:       set() 函数创建一个无序不重复元素集,可进行关系测试,删除重复数据,还可以计算交集.差集.并集等. iterable -- 可迭代对象对象:返回新的集合对象. 语法 ...

  4. 实现一个自定义<table>标签

    需求是有两个自定义的标签<table>和<column> <table>有个items属性,负责导入数据 package hello; import java.ut ...

  5. bzoj 2946 [Poi2000]公共串——后缀自动机

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2946 对每个串都建一个后缀自动机,然后 dfs 其中一个自动机,记录同步的话在别的自动机上走 ...

  6. php-excel 与 laravel-excel

    php-excel: http://blog.csdn.net/evkj2013/article/details/65441170 php-excel中文手册(前端的jqury) http://www ...

  7. substr的学习(PHP学习)

    substr的用法: 首先看PHP手册 ,手册上是这样说的 string substr ( string $string , int $start [, int $length ] ) 执行subst ...

  8. 实战 TestNG 监听器

    TestNG 是一个开源的自动化测试框架,其灵感来自 JUnit 和 NUnit,但它引入了一些新功能,使其功能更强大,更易于使用.TestNG 的设计目标是能够被用于进行各种类型测试:单元测试.功能 ...

  9. 小程序mina框架与配置

    小程序是采用MINA框架 <!--demo.wxml--> <view> Hello {{name}}</view> <button bindtap=&quo ...

  10. linux输入子系统概念介绍

    在此文章之前,我们讲解的都是简单的字符驱动,涉及的内容有字符驱动的框架.自动创建设备节点.linux中断.poll机制.异步通知.同步互斥.非阻塞.定时器去抖动. 上一节文章链接:http://blo ...