B. Mike and Fun

Time Limit: 20 Sec  Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/548/problem/A

Description

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 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

Sample Output

3
4
3
3
4
 #include<bits/stdc++.h>
using namespace std; int main() {
int n,m,q,x,y;
int mapp[][];
cin>>n>>m>>q;
for(int i = ; i <= n; i++) {
int total = ;
int maxx = ;
for(int j = ; j <= m; j++) {
scanf("%d",&mapp[i][j]);
if(mapp[i][j] == )
total = ;
total += mapp[i][j];
/**更新该行最大的连续值*/
if(total > maxx) maxx = total;
}
mapp[i][] = maxx;
} int total;
while(q--) {
scanf("%d %d",&x,&y);
/**依题意进行处理*/
if(mapp[x][y] == ) {
mapp[x][y] = ;
} else {
mapp[x][y] = ;
} int maxx = ;
total = ; /**更新该行最大的连续值*/
for(int i = ; i <= m; i++) {
total += mapp[x][i];
if(total > maxx) maxx = total;
if(mapp[x][i] == ) total = ;
} /**找最大的连续值*/
mapp[x][] = maxx;
int ans = mapp[][];
for(int i = ; i <= n; i++) {
if(mapp[i][] > ans) ans = mapp[i][];
}
cout<<ans<<endl;
} return ;
}

Codeforces Round #305 (Div. 2) B. Mike and Fun 暴力的更多相关文章

  1. Codeforces Round #305 (Div. 2) A. Mike and Fax 暴力回文串

     A. Mike and Fax Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/548/pro ...

  2. Codeforces Round #305 (Div. 1) A. Mike and Frog 暴力

     A. Mike and Frog Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/547/pr ...

  3. set+线段树 Codeforces Round #305 (Div. 2) D. Mike and Feet

    题目传送门 /* 题意:对于长度为x的子序列,每个序列存放为最小值,输出长度为x的子序列的最大值 set+线段树:线段树每个结点存放长度为rt的最大值,更新:先升序排序,逐个添加到set中 查找左右相 ...

  4. 数论/暴力 Codeforces Round #305 (Div. 2) C. Mike and Frog

    题目传送门 /* 数论/暴力:找出第一次到a1,a2的次数,再找到完整周期p1,p2,然后以2*m为范围 t1,t2为各自起点开始“赛跑”,谁落后谁加一个周期,等到t1 == t2结束 详细解释:ht ...

  5. 暴力 Codeforces Round #305 (Div. 2) B. Mike and Fun

    题目传送门 /* 暴力:每次更新该行的num[],然后暴力找出最优解就可以了:) */ #include <cstdio> #include <cstring> #includ ...

  6. 字符串处理 Codeforces Round #305 (Div. 2) A. Mike and Fax

    题目传送门 /* 字符串处理:回文串是串联的,一个一个判断 */ #include <cstdio> #include <cstring> #include <iostr ...

  7. Codeforces Round #305 (Div. 1) B. Mike and Feet 单调栈

    B. Mike and Feet Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/547/pro ...

  8. Codeforces Round #305 (Div. 2) D. Mike and Feet 单调栈

    D. Mike and Feet time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

  9. Codeforces Round #305 (Div. 2) D. Mike and Feet

    D. Mike and Feet time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

随机推荐

  1. tk mybatis通用mapper,复杂and or条件查询

    需求:where查询,需要支持(a or b or c) and d 也就是a.b.c三个条件是或的关系,然后再与d相与. 尝试后,可以通过以下方式处理: 方式1:Weekend语法 Weekend& ...

  2. 老男孩python学习之作业一购物小程序

    想学编程由来已久 始终没有个结果,痛心不已 如今再次捡起来,望不负期望,不负岁月 ......一万字的废话...... 先介绍一下我的自学课程吧 "路飞学城"的<python ...

  3. hdu1010 Tempter of the Bone---DFS+奇偶剪枝

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1010 题目描述:根据地图,'S'为开始位置,'D'为门的位置,' . '为空地,'X'为墙,不能经过 ...

  4. WPF设置控件获得焦点

    1.这个比较有效 this.Dispatcher.BeginInvoke(DispatcherPriority.Background, (Action)(() => { Keyboard.Foc ...

  5. scrapy 选择器官方文档

    当抓取网页时,常见的任务是从HTML源码中提取数据.现有的一些库可以达到这个目的: BeautifulSoup lxml Scrapy 提取数据有自己的一套机制.它们被称作选择器(seletors), ...

  6. JavaWeb小项目(一)

    总结一下前段时间,在学了JSP.Servlet.JavaBean后,配合Tomcat服务器加上MySQl数据库搭的第一个简单网站. 前前后后,在学习了以上说的这些概念知识后,还进一步熟悉了整个搭建的流 ...

  7. HTTP首部扫盲

    [TOC] 之前在做web开发时使用到HTTP首部的时候遇到不熟悉的都是现用现查,时间一长印象就不深刻了.最近在重读<图解HTTP>,其中有一章是专门讲解HTTP首部的,讲解的HTTP首部 ...

  8. C# 删除文件夹

    三种方法 1.这种方法简单,能删除文件夹内的所有文件(文件及子目录) DirectoryInfo di = new DirectoryInfo(string Path);         di.Del ...

  9. 极客验证官方demo构建使用及代码分析

    #什么是极客验证? 官方定义:极验验证是一种在计算机领域用于区分自然人和机器人的,通过简单集成的方式,为开发者提供安全.便捷的云端验证服务. #使用命令从github上获取: git clone ht ...

  10. [JLOI 2015]城池攻占

    Description 小铭铭最近获得了一副新的桌游,游戏中需要用 m 个骑士攻占 n 个城池. 这 n 个城池用 1 到 n 的整数表示.除 1 号城池外,城池 i 会受到另一座城池 fi 的管辖, ...