(CodeForces 548B 暴力) Mike and Fun
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.
The first line of input contains three integers n, m 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.
After each round, print the current score of the bears.
5 4 50 1 1 01 0 0 10 1 1 01 0 0 10 0 0 01 11 41 14 24 3
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相关推荐
- Codeforces 798C:Mike and gcd problem
Codeforces 798C:Mike and gcd problem 题目链接:http://codeforces.com/contest/798/problem/C 题目大意:给出一个大小为$n ...
- 【CodeForces - 798A】Mike and palindrome (回文串,水题,字符串问题)
题干: Mike has a string s consisting of only lowercase English letters. He wants to change exactly one ...
- Vicious Keyboard CodeForces - 801A (暴力+模拟)
题目链接 题意: 给定一个字符串,最多更改一个字符,问最多可以有多少个"VK"子串? 思路: 由于数据量很小,不妨尝试暴力写.首先算出不更改任何字符的情况下有多个VK字串,然后尝试 ...
- 【codeforces 798A】Mike and palindrome
[题目链接]:http://codeforces.com/contest/798/problem/A [题意] 让你严格改变一个字符,使得改变后的字符串为一个回文串; 让你输出可不可能; [题解] 直 ...
- CodeForces 1138B暴力+剪枝
[题目链接]Circus [题目分析]理解题意以后发现并没有什么思路,没有什么算法能用,这个时候就应该想到计算机解题的本质--暴力求解.相应的就要想到剪枝的条件,肯定不能盲目的暴力求解. 总共有四种人 ...
- 【Codeforces - 798C】 Mike and gcd problem(思维,贪心)
题干: Mike has a sequence A = [a1, a2, ..., an] of length n. He considers the sequence B = [b1, b2, .. ...
- 【CodeForces - 798D】Mike and distribution (思维构造,贪心,黑科技)
题干: Mike has always been thinking about the harshness of social inequality. He's so obsessed with it ...
- 【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 ...
- 【codeforces 798B】Mike and strings
[题目链接]:http://codeforces.com/contest/798/problem/B [题意] 给你n个字符串; 每次操作,你可以把字符串的每个元素整体左移(最左边那个字符跑到最后面去 ...
最新文章
- 英伟达TRTTorch
- python浅拷贝和深拷贝
- Linux内存描述之概述--Linux内存管理(一)
- 写博客一周我有哪些收获
- bat 复制文件夹_怎么生成电脑上文件夹的目录结构
- 学习Python最好的途径——激发自己的学习兴趣!
- git push --no-thin
- Android 之自定义组件
- log4net 小记
- 获取http地址如何从上面抓取图片_用 Python 自动抓取妹子图
- ASICFPGA中的三态
- __name__的意义与作用
- 4.16-4.22课题(拼团系统)进度汇报
- html ui 下拉列表,html - 如何给样式Material-ui选择字段下拉菜单?
- window下的git工具msysgit的使用
- 高通平台android9.0充电电量,充电指示灯以及充电图标读取分析
- MySQL 之 ROUND 函数四舍五入的陷阱
- svg图放大、缩小、拖拽
- 几何画板在教学中的常见应用
- allegro标注尺寸设置_Allegro中尺寸标注文字的设置