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 50 1 1 01 0 0 10 1 1 01 0 0 10 0 0 01 11 41 14 24 3

output
34334

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

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

转载于:https://www.cnblogs.com/YY56/p/5009281.html

(CodeForces 548B 暴力) Mike and Fun相关推荐

  1. Codeforces 798C:Mike and gcd problem

    Codeforces 798C:Mike and gcd problem 题目链接:http://codeforces.com/contest/798/problem/C 题目大意:给出一个大小为$n ...

  2. 【CodeForces - 798A】Mike and palindrome (回文串,水题,字符串问题)

    题干: Mike has a string s consisting of only lowercase English letters. He wants to change exactly one ...

  3. Vicious Keyboard CodeForces - 801A (暴力+模拟)

    题目链接 题意: 给定一个字符串,最多更改一个字符,问最多可以有多少个"VK"子串? 思路: 由于数据量很小,不妨尝试暴力写.首先算出不更改任何字符的情况下有多个VK字串,然后尝试 ...

  4. 【codeforces 798A】Mike and palindrome

    [题目链接]:http://codeforces.com/contest/798/problem/A [题意] 让你严格改变一个字符,使得改变后的字符串为一个回文串; 让你输出可不可能; [题解] 直 ...

  5. CodeForces 1138B暴力+剪枝

    [题目链接]Circus [题目分析]理解题意以后发现并没有什么思路,没有什么算法能用,这个时候就应该想到计算机解题的本质--暴力求解.相应的就要想到剪枝的条件,肯定不能盲目的暴力求解. 总共有四种人 ...

  6. 【Codeforces - 798C】 Mike and gcd problem(思维,贪心)

    题干: Mike has a sequence A = [a1, a2, ..., an] of length n. He considers the sequence B = [b1, b2, .. ...

  7. 【CodeForces - 798D】Mike and distribution (思维构造,贪心,黑科技)

    题干: Mike has always been thinking about the harshness of social inequality. He's so obsessed with it ...

  8. 【CodeForces - 689B】Mike and Shortcuts(Dijkstra最短路,或者bfs跑状态类似spfa)

    题干: Recently, Mike was very busy with studying for exams and contests. Now he is going to chill a bi ...

  9. 【codeforces 798B】Mike and strings

    [题目链接]:http://codeforces.com/contest/798/problem/B [题意] 给你n个字符串; 每次操作,你可以把字符串的每个元素整体左移(最左边那个字符跑到最后面去 ...

最新文章

  1. 英伟达TRTTorch
  2. python浅拷贝和深拷贝
  3. Linux内存描述之概述--Linux内存管理(一)
  4. 写博客一周我有哪些收获
  5. bat 复制文件夹_怎么生成电脑上文件夹的目录结构
  6. 学习Python最好的途径——激发自己的学习兴趣!
  7. git push --no-thin
  8. Android 之自定义组件
  9. log4net 小记
  10. 获取http地址如何从上面抓取图片_用 Python 自动抓取妹子图
  11. ASICFPGA中的三态
  12. __name__的意义与作用
  13. 4.16-4.22课题(拼团系统)进度汇报
  14. html ui 下拉列表,html - 如何给样式Material-ui选择字段下拉菜单?
  15. window下的git工具msysgit的使用
  16. 高通平台android9.0充电电量,充电指示灯以及充电图标读取分析
  17. MySQL 之 ROUND 函数四舍五入的陷阱
  18. svg图放大、缩小、拖拽
  19. 几何画板在教学中的常见应用
  20. allegro标注尺寸设置_Allegro中尺寸标注文字的设置

热门文章

  1. linux下安装redmine1.2.1全记录
  2. 想成为软件架构师,你的举止够优雅吗?
  3. BCH链上交易量剧增,超越莱特币
  4. 自适应游标共享技术01(Adaptive Cursor Sharing)
  5. Android项目:proguard混淆之常见开源项目混淆配置
  6. 数据公钥加密和认证中的私钥公钥
  7. IOS Singleton单例模式用法
  8. jboss-as-web-7.0.1.Final 配置 SSL
  9. 寒羽对帝国的理解(通向高手之路)(转)
  10. 给你的开源项目加一个绶带吧