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 ...
随机推荐
- python--同步锁/递归锁/协程
同步锁/递归锁/协程 1 同步锁 锁通常被用来实现对共享资源的同步访问,为每一个共享资源创建一个Lock对象,当你需需要访问该资源时,调用acquire()方法来获取锁对象(如果其他线程已经获得了该锁 ...
- Spark:scala集合转化为DS/DF
scala集合转化为DS/DF case class TestPerson(name: String, age: Long, salary: Double) val tom = TestPerson( ...
- java Thread 接口学习
对于程序员来说 Thread应该都不会陌生,具体的接口调用不是本篇的重点.Thread的基本概念及接口的使用:java多线程 下面将更多的从底层实现角度讲一下Thread. Thread的声明如下: ...
- 闲聊 Exp/Imp 命令使用
1.Exp/Imp 命令可用的参数: 2.userid 参数必须跟在 Exp/Imp 命令的后面,可以省略,如 Exp Userid=用户名/密码@数据库实例名 或者 Exp 用户名/密码@数据库实例 ...
- crypto必知必会
crypto必知必会 最近参加了个ctf比赛,在i春秋,南邮方面刷了一些crypto密码学题目,从中也增长了不少知识,在此关于常见的密码学知识做个小总结! Base编码 Base编码中用的比较多的是b ...
- ASP.NET Core + Docker + Jenkins + gogs + CentOS 从零开始搭建持续集成
为什么不用gitlab? 没有采用gitlab,因为gitlab比较吃配置,至少得2核4G的配置.采用go语言开发的gogs来代替,搭建方便(不到10分钟就能安装完成),资源消耗低,功能也比较强大,也 ...
- jenkins实战(一):war安装及插件安装
一:整体介绍 以下摘自维基百科: Jenkins是一个用Java编写的开源的持续集成工具.在与Oracle发生争执后,项目从Hudson项目复刻. Jenkins提供了软件开发的持续集成服务.它运行在 ...
- Python传递参数的多种方式
Python中根据函数的输入参数以及是否有返回值可分为四种函数: 1.无参数无返回值 2.有参数无返回值 3.无参数有返回值 4.有参数无返回值 Python 中参数传递有下列五种方式; 1.位置传递 ...
- [Luogu 2816]宋荣子搭积木
Description saruka非常喜欢搭积木,他一共有n块积木.而且saruka的积木很特殊,只能一块块的竖着摞,可以摞很多列.说过saruka的是特殊的积木了,这些积木都非常智能,第i块积木有 ...
- 【模板】KMP字符串匹配
题目描述 如题,给出两个字符串s1和s2,其中s2为s1的子串,求出s2在s1中所有出现的位置. 为了减少骗分的情况,接下来还要输出子串的前缀数组next. (如果你不知道这是什么意思也不要问,去百度 ...