zoukankan      html  css  js  c++  java
  • 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

    HINT

    题意

    500×500的矩阵,每次单点修改,把g[i][j]变成1-g[i][j],然后求出在横方向,最长的连续1长度

    题解:

     每次修改,横着暴力修改

    每次查询,竖着暴力更新答案就好

    代码:

    //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;
        }
    }
  • 相关阅读:
    jvm gc 线程
    高分辨率图像建筑物提取数据集制作
    Ubuntu 更改软件源
    后台程序员简单应用前端的bootstrap(小白)
    php--常见算法3
    php--常见算法2
    php--常见算法1
    php三种排序算法
    Django学习之十二:Cache 缓存组件
    Restframe_work 回顾记忆集
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4532399.html
Copyright © 2011-2022 走看看