Codeforces Round #305 (Div. 2) B. Mike and Fun 暴力
2015-05-27 07:42
344 查看
[b] B. Mike and Fun[/b]
Time Limit: 20 Sec Memory Limit: 256 MB题目连接
http://codeforces.com/contest/548/problem/ADescription
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.[b]Sample Input[/b]
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
HINT
[b]题意 [/b]500×500的矩阵,每次单点修改,把g[i][j]变成1-g[i][j],然后求出在横方向,最长的连续1长度
[b]题解:[/b]
每次修改,横着暴力修改
每次查询,竖着暴力更新答案就好
[b]代码:[/b]
//qscqesze #include <cstdio> #include <cmath> #include <cstring> #include <ctime> #include <iostream> #include <algorithm> #include <set> #include <vector> #include <sstream> #include <queue> #include <typeinfo> #include <fstream> #include <map> #include <stack> typedef long long ll; using namespace std; //freopen("D.in","r",stdin); //freopen("D.out","w",stdout); #define sspeed ios_base::sync_with_stdio(0);cin.tie(0) #define test freopen("test.txt","r",stdin) #define maxn 200001 #define mod 1000000007 #define eps 1e-9 int Num; char CH[20]; //const int inf=0x7fffffff; //нчоч╢С const int inf=0x3f3f3f3f; inline ll read() { ll x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } inline void P(int x) { Num=0;if(!x){putchar('0');puts("");return;} while(x>0)CH[++Num]=x%10,x/=10; while(Num)putchar(CH[Num--]+48); puts(""); } //************************************************************************************** int g[3000][3000]; int ans[3000]; int ans2; int main() { //test; int n=read(),m=read(),q=read(); for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) g[i][j]=read(); ans[i]=0; int tmp=0; for(int k=1;k<=m;k++) { if(g[i][k]==1) tmp++; else tmp=0; ans[i]=max(ans[i],tmp); } } for(int i=1;i<=q;i++) { int x,y; x=read(),y=read(); g[x][y]=1-g[x][y]; ans[x]=0; int tmp=0; for(int k=1;k<=m;k++) { if(g[x][k]==1) tmp++; else tmp=0; ans[x]=max(ans[x],tmp); } ans2=0; for(int k=1;k<=n;k++) ans2=max(ans2,ans[k]); cout<<ans2<<endl; } }
相关文章推荐
- 暴力 Codeforces Round #305 (Div. 2) B. Mike and Fun
- Codeforces Round #305 (Div. 2)-Mike and Fun(暴力求解连续1)
- Codeforces Round #305 (Div. 1) A. Mike and Frog 暴力
- Codeforces Round #305 (Div. 2) B. Mike and Fun(水题)
- Codeforces Round #305 (Div. 2) B.Mike and Fun
- Codeforces Round #305 (Div. 2) A. Mike and Fax 暴力回文串
- CF #305 (Div. 2) C. Mike and Frog(扩展欧几里得&&当然暴力is also no problem)
- 数论/暴力 Codeforces Round #305 (Div. 2) C. Mike and Frog
- Codeforces Round #305 (Div. 2)——B.——Mike and Fun
- Codeforces Round #410 (Div. 2)B. Mike and strings(暴力)
- CF#305-B. Mike and Fun-暴力模拟水题
- Codeforces Round #410 (Div. 2)B. Mike and strings(暴力)
- Codeforces Round #305 (Div. 2) C. Mike and Frog +B. Mike and Fun
- Codeforces #410(div2) B. Mike and strings (暴力枚举
- B. Mike and Fun---cf548B(暴力求解)
- Codeforces Round #305 (Div. 2)B. Mike and Fun
- IndiaHacks 2016 - Online Edition (Div. 1 + Div. 2)-C - Bear and Up-Down-暴力枚举
- C. Amr and Chemistry(Codeforces Round #312 (Div. 2) 二进制+暴力)
- Codeforces Round #394 (Div. 2) C. Dasha and Password 暴力
- Codeforces Round #305 (Div. 2)C---Mike and Frog(扩欧+乱搞)