crf inspection (half + prefix and two-dimensional)

The Description 1.1
CRF has a kingdom.
His kingdom is rectangular, spanning the n latitudes and longitudes m area, and in the area at the junction of longitude and latitude of each region
there is a city (that is, the Kingdom crf of a total of n? M cities).
One morning, crf from his 10,000 square meters large bed, he decided to inspect about his kingdom, to check
his implementation of the national plan of brush title.
The news came out, the whole kingdom of various mayors are scared, because there are some lazy mayor has not announced crf universal brush title
plan, so all collective mayor had a meeting, to discuss how to make crf not found their inaction.
They know crf has a bad habit, he only visited the city a square area, but they also know that the more visited the city of
city, crf will be more happy. But once he found crf visited his city did not carry out that policy, he will be very angry, and then
put these exiled mayor to pigs.
Mayors are now looking out of a maximum square so that all cities in the square have been carrying out a full crf
people brush title plan.
1.2 Input
first act input two integers n; m, and the number represents the number of crossings longitude-latitude regions Kingdom crf.
Next n lines, each line has m integers, each integer may only 0 or 1, 0 indicates that the city did not implement crf the
national title brush plan, 1 has been implemented.
1.3 Output
outputs a number k, the maximum side length of a square.
The Sample 1.4
the Sample the Sample the Input the Output
3 3
. 1. 1 0
. 1. 1. 1
. 1. 1. 1
2
for 1.5 Hint
for 30% of the data, to ensure that 1≤? N, m? ≤30.
100% of the data, ensure 1≤? N, m≤? 2000.


 

Problem-solving ideas:

First-half the length of a side mid, n-side upper left endpoint enumeration, and count the number of two-dimensional prefix to the mid value of the side length of the square 0, 0 If the number is 0, then set up, at the upper left or an enum endpoint

code show as below:

#include<bits/stdc++.h>
using namespace std;
const int N = 2010;
int n, m;
int mapp[N][N];
int cnt[N][N];
inline int read(){
    int 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;
}
bool judge(int x){
    for(int i=1; i+x-1<=n; i++)
        for(int j=1; j+x-1<=m; j++)
            if(cnt[i+x-1][j+x-1] - cnt[i+x-1][j-1] - cnt[i-1][j+x-1] + cnt[i-1][j-1] == 0) return 1;
    return 0;
}
int main(){
    freopen ("inspect.in", "r", stdin);
    freopen ("inspect.out", "w", stdout);
    scanf("%d%d", &n ,&m);
    for(register int i=1; i<=n; i++){
        for(register int j=1; j<=m; j++){
            scanf("%d",mapp[i][i]);
            mapp[i][j]^=1;
            cnt[i][j] = (cnt[i-1][j] + cnt[i][j-1] - cnt[i-1][j-1] + mapp[i][j]);      
        }
    }
    int l=0, r=2000;
    while(l < r){
        int mid = ((l + r) >> 1) + 1;
        if(judge( mid ) ) l=mid;
        else r = mid - 1;
    }
    printf("%d", l);
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/tonyshen/p/11369655.html