题目连接

  • 题意:

    给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&#39;s Digital Board的更多相关文章

  1. Codeforces Round #248 (Div. 1)——Ryouko&#39;s Memory Note

    题目连接 题意: 给n和m,一行m个1<=x<=n的数.记c=.如今仅仅能选择一个数x变成y,序列中全部等于x的值都变成y,求最小的c 分析: 对于一个数x,把与他相邻的所有的非x的数所有 ...

  2. 构造水题 Codeforces Round #206 (Div. 2) A. Vasya and Digital Root

    题目传送门 /* 构造水题:对于0的多个位数的NO,对于位数太大的在后面补0,在9×k的范围内的平均的原则 */ #include <cstdio> #include <algori ...

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

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

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

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

  6. Codeforces Round #248 (Div. 2) C. Ryouko's Memory Note

    题目链接:http://codeforces.com/contest/433/problem/C 思路:可以想到,要把某一个数字变成他的相邻中的数字的其中一个,这样总和才会减少,于是我们可以把每个数的 ...

  7. Codeforces Round #248 (Div. 2)C 题

    题目:http://codeforces.com/contest/433/problem/C 没想到做法就各种纠结, 今天做的都快疯掉了, 太弱了, 等题解一出,就各种恍然大悟 不应该不应该 正文: ...

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

  9. Codeforces Round #313 (Div. 1) Gerald&#39;s Hexagon

    http://codeforces.com/contest/559/problem/A 题目大意:按顺序给出一个各内角均为120°的六边形的六条边长,求该六边形能分解成多少个边长为1的单位三角形. 解 ...

随机推荐

  1. uva Matrix Decompressing (行列模型)

    Matrix Decompressing 题目:    给出一个矩阵的前i行,前j列的和.要求你求出满足的矩阵. 矩阵的数范围在[1,20].   一開始就坑在了这里.没读细致题目. 囧...   事 ...

  2. Java.util.zip adding a new file overwrites entire jar?(转)

    ZIP and TAR fomats (and the old AR format) allow file append without a full rewrite. However: The Ja ...

  3. 引用类中的enum

    引用类中的enum 引用类中的enum,需要加类的域class_name::value_in_enum_name 点击(此处)折叠或打开 #include <stdio.h> #inclu ...

  4. Spark&amp;Spark性能调优实战

    Spark特别适用于多次操作特定的数据,分mem-only和mem & disk.当中mem-only:效率高,但占用大量的内存,成本非常高;mem & disk:内存用完后,会自己主 ...

  5. ubuntu12 环境下编译freerdp

    有时候需要从linux环境下远程连接到windows的环境,可以采用freerdp.freerdp是一个linux下开源的工具,在Ubuntu下可以直接用 apt-get install freerd ...

  6. A Game of Thrones(20) - Eddard

    Eddard Stark rode through the towering bronze doors of the Red Keep sore, tired, hungry, and irritab ...

  7. 无向图的最短路径算法JAVA实现(转)

    一,问题描述 给出一个无向图,指定无向图中某个顶点作为源点.求出图中所有顶点到源点的最短路径. 无向图的最短路径其实是源点到该顶点的最少边的数目. 本文假设图的信息保存在文件中,通过读取文件来构造图. ...

  8. 一种单片机支持WiFi的应用——SimpleWiFi在单片机中的应用

    一种单片机支持WiFi的应用——SimpleWiFi在单片机中的应用 先上图: 现在的智能控制都是基于微控制器,随着智能的手持终端的普及,基于智能终端的控制就会越来越普遍. WIFI便是其中的一种.W ...

  9. 2013 吉林通化邀请赛 Play Game 记忆化搜索

    dp[ba][ta][bb][tb]表示a堆牌从下面拿了ba张,从上面拿了ta张.b堆牌从下面拿了bb张,从上面拿了tb张.当前玩家能得到的最大的分数. 扩展方式有4种,ba+1,ta+1,bb+1, ...

  10. Linux目录文件详解FHS标准(2013.09.05)

    Linux 目录配置的依据FHS(Filesystem Hierarchy Standard)标准,将目录分成为四种交互作用的形态: 四种形态的具体解释: 可分享的:可以分享给其他系统挂载使用的目录, ...