[Usaco3.3.4]range

Source: Internet
Author: User

Topic Portal: Http://www.nocow.cn/index.php/Translate:USACO/range

If this problem is not done before the same topic, I think I can not do it, probably is pre-treatment s[i][j], the first I row before the J column number of 1, and then O (1) time to determine whether the square has 1.

S[I][J] is obviously equal to s[i-1][j]+s[i][j-1]-s[i-1][j-1]+f[i][j] (two polygons repeating part is s[i-1][j-1])

And judging from line I to line l, column J to page K in this polygon there is no (j-k+1) * (l-i+1) 1, obviously only to determine whether s[i][j]-s[i-1][k]-s[l][j-1]+s[i-1][j-1] equals (j-k+1) * (l-i+1) On the line. (the repeating portion of two polygons is s[i-1][j-1])

There will be a bit of chaos, but just think about the diagram, and this problem is square, as long as the length of the enumeration side is good.

  

/*id:abc31261lang:c++task:range*/#include <cstdio> #include <cstring> #include <iostream>using namespace Std;const int Maxn=260;int n,f[maxn][maxn],s[maxn][maxn],num[maxn];int main () {int I,j,l;freopen ("range.in" , "R", stdin), Freopen ("Range.out", "w", stdout), scanf ("%d", &n), for (i=1;i<=n;i++) for (j=1;j<=n;j++) scanf (" %01d ", &f[i][j]); Memset (s,0,sizeof (s)); memset (num,0,sizeof (num)); for (i=1;i<=n;i++) for (j=1;j<=n;j++) s[ I][j]=s[i-1][j]+s[i][j-1]-s[i-1][j-1]+f[i][j];for (i=1;i<=n;i++) for (j=1;j<=n;j++) for (L=2;l<=min (n-i+1, n-j+1); l++) {int x=i+l-1,y=j+l-1;if (s[x][y]-s[x][j-1]-s[i-1][y]+s[i-1][j-1]==l*l) num[l]++;} for (i=1;i<=n;i++) if (num[i]!=0) printf ("%d%d\n", I,num[i]); return 0;}

  

[Usaco3.3.4]range

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.