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)为下边界的情况,h=(x,y)上边最多的连续1的个数。那么递减的枚举,对于当前hx,仅仅须要看两側能到达的最远距离,使得h(x,ty)不大于h就可以。之后的枚举得到的两側距离大于等于之前的,所以继续之前的两側距离继续枚举就可以。
const int maxn = 1100; int n, m, q;
int ipt[maxn][maxn];
int up[maxn][maxn], dwn[maxn][maxn], lft[maxn][maxn], rht[maxn][maxn];
int len[maxn];
void updaterow(int r)
{
FE(j, 1, m)
lft[r][j] = (ipt[r][j] == 1 ? lft[r][j - 1] + 1 : 0);
FED(j, m, 1)
rht[r][j] = (ipt[r][j] == 1 ? rht[r][j + 1] + 1 : 0);
}
void updatecol(int c)
{
FE(i, 1, n)
up[i][c] = (ipt[i][c] == 1 ? up[i - 1][c] + 1 : 0);
FED(i, n, 1)
dwn[i][c] = (ipt[i][c] == 1 ? dwn[i + 1][c] + 1 : 0);
}
int maxarea(int s, int len[], int thes)
{
int l = s, r = s, ret = 0;
FED(i, len[s], 1)
{
while (l >= 1 && len[l] >= i)
l--;
while (r <= thes && len[r] >= i)
r++;
ret = max(ret, i * (r - l - 1));
}
return ret;
} int main()
{
while (~RIII(n, m, q))
{
FE(i, 1, n) FE(j, 1, m)
RI(ipt[i][j]);
FE(i, 1, n)
updaterow(i);
FE(j, 1, m)
updatecol(j);
REP(kase, q)
{
int op, x, y;
RIII(op, x, y);
if (op == 1)
{
ipt[x][y] ^= 1;
updatecol(y);
updaterow(x);
}
else
{
int ans = max(maxarea(y, up[x], m), maxarea(y, dwn[x], m));
FE(i, 1, n)
len[i] = lft[i][y];
ans = max(ans, maxarea(x, len, n));
FE(i, 1, n)
len[i] = rht[i][y];
ans = max(ans, maxarea(x, len, n));
WI(ans);
}
}
}
return 0;
}
Codeforces Round #248 (Div. 1)——Nanami's Digital Board的更多相关文章
- Codeforces Round #248 (Div. 1)——Ryouko's Memory Note
题目连接 题意: 给n和m,一行m个1<=x<=n的数.记c=.如今仅仅能选择一个数x变成y,序列中全部等于x的值都变成y,求最小的c 分析: 对于一个数x,把与他相邻的所有的非x的数所有 ...
- 构造水题 Codeforces Round #206 (Div. 2) A. Vasya and Digital Root
题目传送门 /* 构造水题:对于0的多个位数的NO,对于位数太大的在后面补0,在9×k的范围内的平均的原则 */ #include <cstdio> #include <algori ...
- 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 ...
- Codeforces Round #248 (Div. 2) (ABCD解决问题的方法)
比赛链接:http://codeforces.com/contest/433 A. Kitahara Haruki's Gift time limit per test:1 second memory ...
- Codeforces Round #248 (Div. 1) D - Nanami's Power Plant 最小割
D - Nanami's Power Plant 思路:类似与bzoj切糕那道题的模型.. #include<bits/stdc++.h> #define LL long long #de ...
- Codeforces Round #248 (Div. 2) C. Ryouko's Memory Note
题目链接:http://codeforces.com/contest/433/problem/C 思路:可以想到,要把某一个数字变成他的相邻中的数字的其中一个,这样总和才会减少,于是我们可以把每个数的 ...
- Codeforces Round #248 (Div. 2)C 题
题目:http://codeforces.com/contest/433/problem/C 没想到做法就各种纠结, 今天做的都快疯掉了, 太弱了, 等题解一出,就各种恍然大悟 不应该不应该 正文: ...
- Codeforces Round #248 (Div. 1) A. Ryouko's Memory Note 水题
A. Ryouko's Memory Note 题目连接: http://www.codeforces.com/contest/434/problem/A Description Ryouko is ...
- Codeforces Round #313 (Div. 1) Gerald's Hexagon
http://codeforces.com/contest/559/problem/A 题目大意:按顺序给出一个各内角均为120°的六边形的六条边长,求该六边形能分解成多少个边长为1的单位三角形. 解 ...
随机推荐
- hadoop format过程
private static boolean format(Configuration conf, boolean isConfirmationNeeded ) throws IOException ...
- CArray
CArray是windows下的相当于动态数组的模板类.用起来及其方便,近期由于需要在JNI下的C语言中使用,自己参考CArray类函数,及其自己需要使用到的部分函数用C++实现出来,以供自己使用,在 ...
- jquery 学习 (二)
1)jquery对象和dom对象区别及相互转换 2)jquery和其他库冲突解决 3)css选择器和jquery选择器 3.1)基本选择器(id选择器.类选择器.元素选择器.*选择器.多个选择器以逗号 ...
- HNCU1099:堆积木
http://hncu.acmclub.com/index.php?app=problem_title&id=111&problem_id=1099 题目描述 小明的侄子要过生日了,小 ...
- Mysql主键索引、唯一索引、普通索引、全文索引、组合索引的区别
原文:Mysql主键索引.唯一索引.普通索引.全文索引.组合索引的区别 Mysql索引概念: 说说Mysql索引,看到一个很少比如:索引就好比一本书的目录,它会让你更快的找到内容,显然目录(索引)并不 ...
- 深入 CSocket 编程之阻塞和非阻塞模式
有时,花上几个小时阅读.调试.跟踪优秀的源码程序,能够更快地掌握某些技术关键点和精髓.当然,前提是对这些技术大致上有一个了解. 我通过几个采用 CSocket 类编写并基于 Client/Server ...
- VSTO学习笔记(十五)Office 2013 初体验
原文:VSTO学习笔记(十五)Office 2013 初体验 Office 2013 近期发布了首个面向消费者的预览版本,我也于第一时间进行了更新试用.从此开始VSTO系列全面转向Office 201 ...
- 红黑树-Python实现
#coding:utf8 #author:HaxtraZ #description:红黑树,python实现 RED = 'red' BLACK = 'black' class RBT: def __ ...
- C++技术问题总结-第11篇 网络通信中主机序网络序
网络通信常常涉及到字节序转化,接下来理解主机序和网络序有什么异同. ①主机字节顺序HBO(Host Byte Order) 採用小头序(little-endian),从低到高的顺序存储. 低位字节排放 ...
- Inno Setup打包添加和去除管理员权限
原文:Inno Setup打包添加和去除管理员权限 添加管理员权限 1.在[Setup]节点添加 PrivilegesRequired=admin 2.进入安装目录,找到文件SetupLdr.e32, ...