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
     
  • 相关阅读:
    MYSQL的基本语法
    如何实现SQL Server临时表的创建?
    计算时间 相加,相减 的方法,TimeSpan 数据转换
    sql server 拆分字符串,拆分两次(:和;)
    SQL group by分组查询(转)
    转: sqlserver常用sql语句,更改字段,建立唯一键,多个字段去重复等
    asp.net,CSS设置<TableListView>的title居左,居左,居上
    linq to sql ,将var 类型转为 IList 类型
    Open XML的上传、下载 、删除 ......文件路径
    C#操作office进行Excel图表创建,保存本地,word获取
  • 原文地址:https://www.cnblogs.com/gaojunonly1/p/10624050.html
Copyright © 2011-2022 走看看