La 3029 City Game (scanning method)

Source: Internet
Author: User

Topic links

Idea: Process Each lattice: calculates the largest rectangle that contains it.

UP[I][J]: The height of the storage rectangle;

LEFT[I][J]: The column number that stores the left edge of the rectangle;

RIGHT[I][J]: Stores the column number of the right boundary of the rectangle.

Area = up[i][j] * (Right[i][j]-left[i][j] +1).

Experience: Even with ideas, write code before you draw on paper, simulation. Otherwise, like the code in the notice of the place, written in 0, it is estimated that debug half a day do not know where the wrong.

#include <algorithm> #include <iostream> #include <cstring> #include <cstdio> #include < string> #include <stack> #include <queue> #include <set> #include <map>typedef long long ll; using namespace std;const int inf=0x3f3f3f3f;const int maxn=1e3+10;int mat[maxn][maxn],up[maxn][maxn];int MYLEFT[MAXN] [Maxn],myright[maxn][maxn];int M,n;int Main () {int t;scanf ("%d", &t), while (t--) {scanf ("%d%d", &m,&n); char ch;for (int i=0;i<m;i++) {for (int j=0;j<n;j++) {Ch=getchar (), while (ch!= ' R ' && ch!= ' F ') Ch=getchar (); if (ch== ' R ') Mat[i][j]=1;else mat[i][j]=0;}} /*for (int i=0;i<m;i++) {for (int j=0;j<n;j++) {printf ("%d", Mat[i][j]);} printf ("\ n");} */int ans=0,i,j;for (i=0;i<m;i++) {//from top to bottom scan int Lo=-1,ro=n;//lo represents the column number of the left obstacle, ro the same. for (j=0;j<n;j++) {//left-to-right scanning, processing up[][] and left[][]. if (mat[i][j]==1) {lo=j;up[i][j]=0;myleft [i][j]=0;} Else{up[i][j]= (i==0?1:up[i-1][j]+1); myleft[i][j]= (I==0?lo+1:max (myleft[i-1][j],lo+1));//!!!}} for (int j=n-1;j>=0;j--) {//right-to-left scanning, processing right[][]. if (mat[i][j]==1) {ro=j;myright[i][j]=n;//attention to detail}else{myright[i][j]= (I==0?ro-1:min (myright[i-1][j],ro-1));//!!! Ans=max (ans,up[i][j]* (myright[i][j]-myleft[i][j]+1));}} printf ("%d\n", ans*3);} return 0;}

  

La 3029 City Game (scanning method)

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.