题意:给定一个n*m的矩阵,都是01矩阵,然后每次一个询问,改变一个格的值,然后问你最大有数是多少。

析:就是按他说的模拟,要预处理,只要把每行的最大值记下来,当改变时,再更新这一行的最大值。

代码如下:

#include<bits/stdc++.h>

using namespace std;
const int maxn = 500 + 5;
int a[maxn][maxn];
int num[maxn]; int main(){
int n, m, q, x, y;
while(cin >> n >> m >> q){
for(int i = 0; i < n; ++i)
for(int j = 0; j < m; ++j)
scanf("%d", &a[i][j]);
int mm = 0;
int tt ;
for(int i = 0; i < n; ++i){
int cnt = 0;
for(int j = 0; j < m; ++j){
if(a[i][j]) ++cnt;
else cnt = 0;
num[i] = max(num[i], cnt);
}
} while(q--){
scanf("%d %d", &x, &y);
--x, --y;
a[x][y] = a[x][y] ? 0 : 1;
int cnt = 0;
num[x] = 0;
for(int i = 0; i < m; ++i){
if(a[x][i]) ++cnt;
else cnt = 0;
num[x] = max(num[x], cnt);
}
mm = 0;
for(int i = 0; i < n; ++i) mm = max(mm, num[i]);
printf("%d\n", mm);
} }
return 0;
}

CodeForces 548B Mike and Fun (模拟)的更多相关文章

  1. Codeforces 548B Mike and Fun

    传送门 B. Mike and Fun time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  2. hdu4135-Co-prime & Codeforces 547C Mike and Foam (容斥原理)

    hdu4135 求[L,R]范围内与N互质的数的个数. 分别求[1,L]和[1,R]和n互质的个数,求差. 利用容斥原理求解. 二进制枚举每一种质数的组合,奇加偶减. #include <bit ...

  3. codeforces 547E Mike and Friends

    codeforces 547E Mike and Friends 题意 题解 代码 #include<bits/stdc++.h> using namespace std; #define ...

  4. CodeForces.158A Next Round (水模拟)

    CodeForces.158A Next Round (水模拟) 题意分析 校赛水题的英文版,坑点就是要求为正数. 代码总览 #include <iostream> #include &l ...

  5. codeforces 689 Mike and Shortcuts(最短路)

    codeforces 689 Mike and Shortcuts(最短路) 原题 任意两点的距离是序号差,那么相邻点之间建边即可,同时加上题目提供的边 跑一遍dijkstra可得1点到每个点的最短路 ...

  6. Codeforces 798C. Mike and gcd problem 模拟构造 数组gcd大于1

    C. Mike and gcd problem time limit per test: 2 seconds memory limit per test: 256 megabytes input: s ...

  7. (CodeForces 548B 暴力) Mike and Fun

    http://codeforces.com/problemset/problem/548/B Mike and some bears are playing a game just for fun. ...

  8. CodeForces 689A Mike and Cellphone (模拟+水题)

    Mike and Cellphone 题目链接: http://acm.hust.edu.cn/vjudge/contest/121333#problem/E Description While sw ...

  9. Codeforces 747C:Servers(模拟)

    http://codeforces.com/problemset/problem/747/C 题意:有n台机器,q个操作.每次操作从ti时间开始,需要ki台机器,花费di的时间.每次选择机器从小到大开 ...

随机推荐

  1. Codeforces Round #206 (Div. 1)B(记忆化)

    这题刚开始理解错题意了 以为只能往右和下走 这题挺好的 看题解看了N久啊 二维的DP 第一维表示走到第几步 可以画一个正方形 以左上角斜着划线 第i步走的点只能是第i条线上的点 而dp的第二维 就表示 ...

  2. 高斯消元 分析 && 模板 (转载)

    转载自:http://hi.baidu.com/czyuan_acm/item/dce4e6f8a8c45f13d7ff8cda czyuan 先上模板: /* 用于求整数解得方程组. */ #inc ...

  3. struct TABLE

    struct TABLE { TABLE() {} /* Remove gcc warning */ TABLE_SHARE *s; handler *file; TABLE *next, *prev ...

  4. Dapper使用在WCF上总是说Service找不到

    原因是用Console Application 做宿主的时候,创建的时候默认是Client Profile 4 ,坑爹啊.改成Net framework 4 即可.

  5. BZOJ3218: a + b Problem

    题解: 先做60分... 考虑最小割,连边容量为需要付出的代价.不妨设在s割为黑色,t割为白色. (s,i,b[i])(i,t,w[i]) 关于奇怪,因为不是按份数来的.所以我们这样建图: (i,i+ ...

  6. Eclipse @override报错解决 必须覆盖超类方法

    解决办法:Windows->Preferences-->java->Compiler-->compiler compliance level设置成1.6

  7. codeforces 333A - Secrets

    题意:保证不能正好配齐n,要求输出可以用的最大硬币数. 注意如果用到某种硬币,那么这种硬币就有无穷多个.所以11=3+3+3+3,12=9+9,13=3+3+3+3+3 #include<cst ...

  8. zoj 2027 Travelling Fee

    // 题意 : 一个人要去旅行 给你起点和终点 求最少花费 其中花费为经过路径的总费用减去该路径的中的最大花费段// 直接搜索 稍微加了个剪枝 主要是数据规模小#include <iostrea ...

  9. liunx环境下的mysql数据库配置文件my.conf内的参数含义

    [client]port = 3306socket = /tmp/mysql.sock [mysqld]port = 3306socket = /tmp/mysql.sock basedir = /u ...

  10. 【MySQL】通过select语句把一列数据拼接成一条字符串

    通过 GROUP_CONCAT(如下图)