1 条题解

  • 0
    @ 2017-08-23 14:30:28

    Method 1:二分答案
    ------------------------------------------AC code------------------------------------------

    #include<cstdio>
    
    using namespace std;
    
    const int MAXN = 2005;
    int n, m, g[MAXN][MAXN];
    
    inline int min(int a, int b){
        return a < b ? a : b;
    }
    
    inline int read(){
        int x = 0;
        bool fl = 1;
        char ch = getchar();
        while(ch < '0' || ch > '9'){
            if(ch == '-')   fl = 0;
            ch = getchar();
        }
        while(ch >= '0' && ch <= '9'){
            x = x * 10 + ch - '0';
            ch = getchar();
        }
        return fl ? x : -x;
    }
    
    bool check(int mid){
        for(int i = mid; i <= n; i++){
            for(int j = mid; j <= m; j++){
                int cnt = g[i][j] - g[i][j-mid] - g[i-mid][j] + g[i-mid][j-mid];
                if(cnt >= mid*mid)  return true;
            }
        }
        return false;
    }
    
    int main(){
    //freopen("t1.in", "r", stdin);
    //freopen("t1.out", "w", stdout);
        n = read(), m = read();
        for(int i = 1; i <= n; i++)
            for(int j = 1; j <= m; j++)
                g[i][j] = read(), g[i][j] = g[i][j] + g[i-1][j] + g[i][j-1] - g[i-1][j-1];
        int l = 0, r = min(n, m)+1, ans = 0;
        while(l < r){
            int mid = l+(r-l)/2;
            if(check(mid))
                if(l == mid)    break;
                else    l = mid;
            else    r = mid;
        }
        printf("%d", l);
        return 0;
    }
    
  • 1

信息

难度
(无)
分类
二分查找其他 点击显示
标签
递交数
0
已通过
0
通过率
?
上传者