Bzoj 1567: [Jsoi2008]blue Mary's campaign map

Source: Internet
Author: User

1567: [Jsoi2008]blue Mary's campaign map Time limit:10 Sec Memory limit:162 MB
submit:1011 solved:578
[Submit] [Status] [Discuss] DescriptionBlue Mary has recently been hooked on the RPG game of StarCraft (StarCraft). She is trying to find more campaign maps to further improve her level. Because Blue Mary's technology has reached a certain height, so for a campaign map that can be used in the same way, she will be able to understand this type of battle by playing one, and then she will not be interested in playing this kind of map again. Many of the online maps are of the same play, so Blue Mary needs you to write a program to help her determine which maps belong to the same class. Specifically, Blue Mary has encoded the campaign map as a matrix of n*n, with a 32-bit (signed) positive integer inside each lattice of the matrix. For two matrices, their similarity is defined as the edge length of their largest public square matrix. The greater the similarity of the two matrices, the more likely the two battle maps are to belong to the same class. InputThe first line consists of a positive integer n. The following n rows, each containing n positive integers, represent a matrix of the first battle map. The following n rows, each containing n positive integers, represent a matrix of the second campaign map. Outputcontains only one row. This line has only a positive integer that indicates how similar the two matrices are. Sample Input3
1 2 3
4 5 6
7 8 9
5 6 7
8 9 1
2 3 4

Sample Output2

HINT

Sample explanation:

Sub-matrices:
5 6
8 9
Maximum common matrix for two maps

Conventions:
N<=50

Main topic: side length of the largest common sub-square of two rectangles

The following: O (n^7) violence ... Enumerate edge lengths from large to small

Code:

#include <iostream>#include<cstdio>#include<cstring>using namespacestd;intN;inta[ -][ -],b[ -][ -];inlineintRead () {CharCh=getchar ();intx=0, f=1;  for(;! IsDigit (CH); Ch=getchar ())if(ch=='-') f=-1;  for(; isdigit (ch); Ch=getchar ()) x=x*Ten+ch-'0'; returnx*F;}intMain () {scanf ("%d",&N);  for(intI=1; i<=n;i++)      for(intj=1; j<=n;j++) A[i][j]=read ();  for(intI=1; i<=n;i++)      for(intj=1; j<=n;j++) B[i][j]=read ();  for(inti=n;i>=1; i--){         for(intk=1; k<=n-i+1; k++){             for(intp=1;p <=n-i+1;p + +){                 for(intq=1; q<=n-i+1; q++){                     for(inty=1; y<=n-i+1; y++){                        BOOLflag=true;  for(intj=0; j<i;j++){                             for(intL=0; l<i;l++){                                if(a[k+j][p+l]!=b[q+j][y+L]) {Flag=false;  Break; }                            }                            if(flag==false) Break; }                        if(flag) {printf ("%d\n", i); return 0; }                    }                }            }        }    }    return 0;}

Bzoj 1567: [Jsoi2008]blue Mary's campaign map

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.