Codeforces Round #305 (Div. 2) B. Mike and Fun 暴力
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 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.
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 暴力的更多相关文章
- 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 ...
- 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 ...
- set+线段树 Codeforces Round #305 (Div. 2) D. Mike and Feet
题目传送门 /* 题意:对于长度为x的子序列,每个序列存放为最小值,输出长度为x的子序列的最大值 set+线段树:线段树每个结点存放长度为rt的最大值,更新:先升序排序,逐个添加到set中 查找左右相 ...
- 数论/暴力 Codeforces Round #305 (Div. 2) C. Mike and Frog
题目传送门 /* 数论/暴力:找出第一次到a1,a2的次数,再找到完整周期p1,p2,然后以2*m为范围 t1,t2为各自起点开始“赛跑”,谁落后谁加一个周期,等到t1 == t2结束 详细解释:ht ...
- 暴力 Codeforces Round #305 (Div. 2) B. Mike and Fun
题目传送门 /* 暴力:每次更新该行的num[],然后暴力找出最优解就可以了:) */ #include <cstdio> #include <cstring> #includ ...
- 字符串处理 Codeforces Round #305 (Div. 2) A. Mike and Fax
题目传送门 /* 字符串处理:回文串是串联的,一个一个判断 */ #include <cstdio> #include <cstring> #include <iostr ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- pythonllk
字符编码 数据类型 函数 装饰器 内置函数 迭代器 生成器 异常 反射 模块 类 对象 类的进阶 socket 进程线程 httphtmlcssJavaScriptjquery MysqlMysq ...
- SecureCRT安装
第一步:下载SecureCRT&SecureCRT激活工具 首先下载SecureCRT安装包和SecureCRT激活工具,SecureCRT&SecureCRT激活工具下载地址:链接: ...
- PageRank之基于C C#的基本实现
重点不是说PageRank是什么,而是怎么用代码实现 什么是PageRank? PageRank,网页排名,又称网页级别.Google左侧排名或佩奇排名,是一种由[1] 根据网页之间相互的超链接计算 ...
- 1.2WEB API 跨域
详细请参考http://www.cnblogs.com/landeanfen/p/5177176.html 在项目上面使用Nuget安装 microsoft.aspnet.webapi.cors 在w ...
- url的解码方式
#coding:utf-8 import urllib legal_person_string = "%E6%B3%95%E5%AE%9A%E4%BB%A3%E8%A1%A8%E4%BA%B ...
- Menubutton按钮弹出菜单
#按钮弹出菜单 from tkinter import * root =Tk() def callback(): print('我被调用了') m = Menubutton(root,text = ' ...
- jacascript AJAX 学习
前言:这是笔者学习之后自己的理解与整理.如果有错误或者疑问的地方,请大家指正,我会持续更新! AJAX 是 asynchronous javascript and XML 的简写,就是异步的 java ...
- 20180117MySQL出现Waiting for table metadata lock的原因以及解决方法
转自http://www.cnblogs.com/digdeep/p/4892953.html 转自:http://ctripmysqldba.iteye.com/blog/1938150 (有修改) ...
- 存储过程学习笔记(SQL数据库
一. 存储过程简介 Sql Server的存储过程是一个被命名的存储在服务器上的Transacation-Sql语句集合,是封装重复性工作的一种方法,它支持用户声明的变量.条件执行和其他强大的编程 ...
- js变量的生命周期
1.在JavaScript中,对于for循环中定义的i变量,其生命周期在循环结束后仍然是有效的. for (var i=0; i < 10; i++){ doSomething(i); } al ...