HDU Computer College College Student Program Design Contest (1006)

Source: Internet
Author: User

Test instructions

There is a 01 matrix of N*n (n<=1000)

Q Inquiry (1000) each query has several sub-rectangles that are all one and greater than or equal to K

Preprocessing from lower right corner to upper right corner
Each point has an R x v
R for how many consecutive 1 on the right
x represents how many 1 consecutive
V represents the maximum number of matrices with this as the upper-left corner
So v[i][j]= min (r[i][j+1], x[i+1][j],v[i+1][j+1]) +1

r[i][j]=r[i][j+1]+1;

x[i][j]=x[i+1][j]+1;

Then ans[v[i][j]]++

Pre-processing suffix and O 1 output

#include <cstdio>#include<cstring>#include<string>#include<iostream>#include<algorithm>#include<map>using namespacestd;Const intn=50005;intn,k,m;ints[1005];intv[1005][1005],r[1005][1005],x[1005][1005],a[1005][1005];Charc[1005];intMain () {inti,j; intT; scanf ("%d",&T);  while(t--) {scanf ("%d%d",&n,&m); memset (s),0,sizeof(s)); Memset (R,0,sizeof(R)); memset (x,0,sizeof(x));  for(i=1; i<=n; i++) {scanf ("%s", c);  for(j=0; j<n;j++) A[i][j+1]=c[j]-'0'; } x[n+1][n]=0; R[n][n+1]=0; V[n+1][n+1]=0;  for(I=n; i>=1; i--)        {             for(J=n; j>=1; j--)            {                if(A[i][j]) {V[i][j]=min (min (v[i+1][j+1],r[i][j+1]), x[i+1][j]); R[I][J]=r[i][j+1]+1; X[I][J]=x[i+1][j]+1; V[I][J]++; }                ElseV[i][j]=r[i][j]=x[i][j]=0; S[V[I][J]]++; }        }         for(i=n-1; i>=1; i--) {S[i]+=s[i+1]; }         while(m--) {scanf ("%d",&k); cout<<s[k]<<Endl; }    }    return 0;}

  

HDU Computer College College Student Program Design Contest (1006)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.