zoukankan      html  css  js  c++  java
  • codeforces548B

    Mike and Fun

     CodeForces - 548B 

    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.

    Examples

    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
    Output
    3
    4
    3
    3
    4

    sol:直接暴力模拟就可以了,每次修改一个点,只会影响一行的答案,所以只要修改一行就可以了,O(Q*m)水过。。。
    #include <bits/stdc++.h>
    using namespace std;
    typedef int ll;
    inline ll read()
    {
        ll s=0;
        bool f=0;
        char ch=' ';
        while(!isdigit(ch))
        {
            f|=(ch=='-'); ch=getchar();
        }
        while(isdigit(ch))
        {
            s=(s<<3)+(s<<1)+(ch^48); ch=getchar();
        }
        return (f)?(-s):(s);
    }
    #define R(x) x=read()
    inline void write(ll x)
    {
        if(x<0)
        {
            putchar('-'); x=-x;
        }
        if(x<10)
        {
            putchar(x+'0');    return;
        }
        write(x/10);
        putchar((x%10)+'0');
        return;
    }
    #define W(x) write(x),putchar(' ')
    #define Wl(x) write(x),putchar('
    ')
    const int N=505;
    int n,m,Q,a[N][N];
    int ans[N];
    int main()
    {
        int i,j;
        R(n); R(m); R(Q);
        for(i=1;i<=n;i++)
        {
            for(j=1;j<=m;j++) R(a[i][j]);
        }
        for(i=1;i<=n;i++)
        {
            int tmp=0;
            for(j=1;j<=m;j++)
            {
                if(a[i][j]) tmp++;
                else tmp=0;
                ans[i]=max(ans[i],tmp);
            }
        }
        while(Q--)
        {
            int x,y,Max=0;
            R(x); R(y);
            a[x][y]^=1;
            int tmp=0; ans[x]=0;
            for(i=1;i<=m;i++)
            {
                if(a[x][i]) tmp++;
                else tmp=0;
                ans[x]=max(ans[x],tmp);
            }
            for(i=1;i<=n;i++) Max=max(Max,ans[i]);
            Wl(Max);
        }
        return 0;
    }
    /*
    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
    output
    3
    4
    3
    3
    4
    */
    View Code
     
  • 相关阅读:
    TCP报文指针解释,IP地址
    Linux基本操作及安装(部分)
    Windows cmd用语
    三次握手,四次挥手
    Linux命令(部分)
    Linux系统命令。
    三层交换配置流程
    网络基本内容(部分)
    20192020学期20192404《网络空间安全专业导论》第三周学习总结
    201920201学期 20192404 《网络空间安全导论》第二周学习总结
  • 原文地址:https://www.cnblogs.com/gaojunonly1/p/10624050.html
Copyright © 2011-2022 走看看