http://codeforces.com/problemset/problem/548/B

Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n × m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes.

They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears.

Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row.

Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round.

Input

The first line of input contains three integers nm and q (1 ≤ n, m ≤ 500 and 1 ≤ q ≤ 5000).

The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0(for mouth) or 1 (for eyes).

The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≤ i ≤ n and 1 ≤ j ≤ m), the row number and the column number of the bear changing his state.

Output

After each round, print the current score of the bears.

Sample test(s)
input
5 4 5
0 1 1 0
1 0 0 1
0 1 1 0
1 0 0 1
0 0 0 0
1 1
1 4
1 1
4 2
4 3
output
3
4
3
3
4

题意理解错, 唉, 白白错了两次, 粘个代码警示一下自己

#include<iostream>
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
using namespace std; #define N 550 int v[N][N]; int Find(int a[], int m)
{
int i, num=, Max=;
for(i=; i<=m; i++)
{
if(a[i]==)
num++;
else
{
Max = max(Max, num);
num = ;
}
} Max = max(Max, num); return Max;
} int FindMax(int a[], int n)
{
int i, Max = ; for(i=; i<=n; i++)
Max = max(Max, a[i]); return Max;
} int main()
{
int n, m, q; while(scanf("%d%d%d", &n, &m, &q)!=EOF)
{
int i, j, I, J, a[N], Max; memset(a, , sizeof(a));
memset(v, , sizeof(v)); for(i=; i<=n; i++)
{
for(j=; j<=m; j++)
{
scanf("%d", &v[i][j]);
a[i] = Find(v[i], m);
}
} for(i=; i<=q; i++)
{
scanf("%d%d", &I, &J);
if(v[I][J])
{
v[I][J] = ;
a[I] = Find(v[I], m); Max = FindMax(a, n);
printf("%d\n", Max);
}
else
{
v[I][J] = ;
a[I] = Find(v[I], m); Max = FindMax(a, n);
printf("%d\n", Max);
}
}
}
return ;
}

(CodeForces 548B 暴力) Mike and Fun的更多相关文章

  1. Codeforces 547C/548E - Mike and Foam 题解

    目录 Codeforces 547C/548E - Mike and Foam 题解 前置芝士 - 容斥原理 题意 想法(口胡) 做法 程序 感谢 Codeforces 547C/548E - Mik ...

  2. Codeforces 548B Mike and Fun

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

  3. CodeForces 548B Mike and Fun (模拟)

    题意:给定一个n*m的矩阵,都是01矩阵,然后每次一个询问,改变一个格的值,然后问你最大有数是多少. 析:就是按他说的模拟,要预处理,只要把每行的最大值记下来,当改变时,再更新这一行的最大值. 代码如 ...

  4. CodeForces 670D1 暴力或二分

    今天,开博客,,,激动,第一次啊 嗯,,先来发水题纪念一下 D1. Magic Powder - 1   This problem is given in two versions that diff ...

  5. codeforces 361 A - Mike and Cellphone

    原题: Description While swimming at the beach, Mike has accidentally dropped his cellphone into the wa ...

  6. Codeforces Round #439 (Div. 2) Problem E (Codeforces 869E) - 暴力 - 随机化 - 二维树状数组 - 差分

    Adieu l'ami. Koyomi is helping Oshino, an acquaintance of his, to take care of an open space around ...

  7. Codeforces Round #439 (Div. 2) Problem A (Codeforces 869A) - 暴力

    Rock... Paper! After Karen have found the deterministic winning (losing?) strategy for rock-paper-sc ...

  8. Codeforces Round #425 (Div. 2) Problem B Petya and Exam (Codeforces 832B) - 暴力

    It's hard times now. Today Petya needs to score 100 points on Informatics exam. The tasks seem easy ...

  9. Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem C (Codeforces 831C) - 暴力 - 二分法

    Polycarp watched TV-show where k jury members one by one rated a participant by adding him a certain ...

随机推荐

  1. python collections 里面的Counter 统计所有出现的字符数量

    from collections import Counter c_num = Counter('Hello world') # 统计出现的每个字符数量print(c_num) for key, va ...

  2. u-boot之内核是怎么启动的

    在u-boot之start_armboot函数分析已经分析过了整个程序框架,但只是说了下什么时候运行内核,并没有具体说明是怎么执行内核的.内核启动分以下几个步骤说明: 1.启动参数bootcmd=na ...

  3. 2Y - sort

    给你n个整数,请按从大到小的顺序输出其中前m大的数.  Input 每组测试数据有两行,第一行有两个数n,m(0<n,m<1000000),第二行包含n个各不相同,且都处于区间[-5000 ...

  4. nginx 启动报错 “/var/run/nginx/nginx.pid" failed” 解决方法

    问题: 重启虚拟机后,再次重启nginx会报错: open() "/var/run/nginx/nginx.pid" failed (2: No such file or dire ...

  5. 20172306《Java程序设计与数据结构》第九周学习总结

    20172306<Java程序设计>第九周学习总结 教材学习内容总结 第十一章: try-catch语句.其中还有finally语句.try是进行某些操作,catch是捕获异常,并通过某些 ...

  6. IDEA 文件列表隐藏某后缀文件

    preferences -> Editor -> File Types -> ignore files and folders   添加后缀类型如:   *.meta

  7. fetch获取json的正确姿势

    fetch要求参数传递,遇到请求无法正常获取数据,网上其他很多版本类似这样: fetch(url ,{ method: 'POST', headers:{ 'Accept': 'application ...

  8. [IBM][CLI Driver][DB2/NT] SQL1101N 不能以指定的授权标识和密码访问节点 "" 上的远程数据库 "LBZM"。 SQLSTATE=08004

    [IBM][CLI Driver][DB2/NT] SQL1101N  不能以指定的授权标识和密码访问节点 "" 上的远程数据库  "LBZM".  SQLST ...

  9. hadoop mapreduce 写入hbase报错 Session 0x0 for server null, unexpected error, closing socket connection and attempting reconnect

    现象:map任务构造数据正常,reduce任务,开始也正常,速度很快 ,在hbase 的管理界面,可以看到,5W以上的请求数 当reduce 执行到 70% 左右的时候,就堵住了,查看yarn的web ...

  10. 2018.11.03 NOIP模拟 树(长链剖分优化dp)

    传送门 考虑直接推式子不用优化怎么做. 显然每一个二进制位分开计算贡献就行. 即记录fi,jf_{i,j}fi,j​表示距离iii这个点不超过jjj的点的每个二进制位的0/10/10/1个数. 但直接 ...