(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 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
- 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的更多相关文章
- Codeforces 547C/548E - Mike and Foam 题解
目录 Codeforces 547C/548E - Mike and Foam 题解 前置芝士 - 容斥原理 题意 想法(口胡) 做法 程序 感谢 Codeforces 547C/548E - Mik ...
- Codeforces 548B Mike and Fun
传送门 B. Mike and Fun time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- CodeForces 548B Mike and Fun (模拟)
题意:给定一个n*m的矩阵,都是01矩阵,然后每次一个询问,改变一个格的值,然后问你最大有数是多少. 析:就是按他说的模拟,要预处理,只要把每行的最大值记下来,当改变时,再更新这一行的最大值. 代码如 ...
- CodeForces 670D1 暴力或二分
今天,开博客,,,激动,第一次啊 嗯,,先来发水题纪念一下 D1. Magic Powder - 1 This problem is given in two versions that diff ...
- codeforces 361 A - Mike and Cellphone
原题: Description While swimming at the beach, Mike has accidentally dropped his cellphone into the wa ...
- 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 ...
- Codeforces Round #439 (Div. 2) Problem A (Codeforces 869A) - 暴力
Rock... Paper! After Karen have found the deterministic winning (losing?) strategy for rock-paper-sc ...
- 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 ...
- 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 ...
随机推荐
- ofo退押金脚本
同事钉钉给的 因为押金一直没退,电话很难打进去,咨询客服排队要等好久,一直几千位. 长时间挂机就自动退出客服了,所以自动写了一个脚本,目前已经成功退押金了.所以共享出来 1.关注ofo小黄车订阅号,注 ...
- gerrit管理下的git代码提交小技巧
1.提交代码git checkout targetbranch 切换至目标分支git pull origin targetbranch 拉取目标分支最新内容git add 修改文件git commit ...
- 如何修改隐藏Zblog/WordPress默认后台登录地址
我相信很多博主站长都遇到过站点被暴力破解,虽然未被破解,但是经常收到那些尝试登录失败的邮件提醒也会心慌慌的.对于这种情况,最好的办法就是修改/隐藏我们的后台登录地址. 关于zblogASP后台登录地址 ...
- 杭电1518 Square(构成正方形) 搜索
HDOJ1518 Square Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- JDK 之 NIO 2 WatchService、WatchKey(监控文件变化)
JDK 之 NIO 2 WatchService.WatchKey(监控文件变化) JDK 规范目录(https://www.cnblogs.com/binarylei/p/10200503.html ...
- wordvec_词的相似度
import gensimfrom gensim.models import word2vecimport loggingimport jiebaimport osimport numpy as np ...
- python 函数调用顺序
def foo(): print ('in the foo') bar() def bar(): print ('in the bar') foo() 1.foo函数进入内存 2.bar函数进入内存 ...
- Bootstrap的起步
-- Bootstrap的起步部分是对Bootstrap的基本了解,有些细节只是在后面的完善时候需要详细阅读. 最基本点还是Css 和组件部分,这部分应该先进行练习....高级阶段是Javascrip ...
- c#里如何实现讲一个字符串数组例如 “112,221”转化成两个字符串数组“112” “221” 中间以逗号隔开
比如是S [0]="123,223" S[1]="111,222" ....... 想转化为 SX[0]="123" SX[1]=" ...
- appium获取package和activity
输入命令adb shell dumpsys window w |findstr \/ |findstr name=然后在手机端打开app,电脑上按enter就即可显示 以微信为例子 appPackag ...