Hang Dian 1505 questions.

http://acm.hdu.edu.cn/showproblem.php?pid=1505

Meaning of the question: The question requires us to find the maximum available area in a given n*m matrix. It is to figure out how large an area can be formed (the largest), and there must be no occupied land in the middle of the largest area.

The second question is similar to the 1506 question, but there are some changes in it, that is, how to turn the "F" (open space) into the height we need? And the tricky thing is that this question is still two-dimensional, which increases the difficulty, so it is necessary to define a two-dimensional h[][] to store the height. So the next step is how to deal with this height problem. The first idea is whether to change the row or the column. Here, the "F" of each group is used, that is, the number of "F" above each position. (The last one is "F"). In this way, all the numbers are calculated. . The next step is to solve it according to the approach of 1506! !

Some notes see the code:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int  maxn=1005;
//char map[maxn];
char a[maxn][maxn];
int h[maxn][maxn],l[maxn],r[maxn];
int n,m;
/*void f()
{
    int i;
    for(i=0;i<m;i++)
    {
         r[i]=i;
         l[i]=i;
    }
}*/
void get_h()
{
   int i,j;
   memset(h,0,sizeof(h));
   for(i=0;i<m;i++)
   {
       h[0][i]=0;//初始化。
   }
   for(i=1;i<=n;i++)
   {
       for(j=0;j<m;j++)
       {
           if(a[i][j]=='F')
           {
               h[i][j]=h[i-1][j]+1;//计算出每个位置以上以及本身的个数(F)。这样就化为高度的处理的方式。
           }
           else
            h[i][j]=0;
       }
   }
}
int get_are()
{
    int i,j;
    f();
    get_h();
    int ans=0,k;
    for(i=1;i<=n;i++)
    {
        memset(l,0,sizeof(l));
        memset(r,0,sizeof(r));
        for(j=0;j<m;j++)
        {
           l[j]=j;//这里必须这样处理,因为如果放到一个函数里处理的话就可能超时。同下。。
            while(h[i][l[j]-1]>=h[i][j]&&l[j]>0)
                //h[i][j]=h[i][l[j]-1];
                l[j]=l[l[j]-1];
        }
        for(j=m-1;j>=0;j--)
        {
            r[j]=j;//
            while(h[i][r[j]+1]>=h[i][j]&&r[j]<m-1)
            {
               // h[i][j]=h[i][r[j]-1];
               r[j]=r[r[j]+1];
            }
        }
        for(j=0;j<m;j++)
        {
               k=(r[j]-l[j]+1)*h[i][j];
               if(ans<k)
                ans=k;
        }
    }
    return ans;
}
int main()
{
    int i,j,t,sum;
    char map[10];
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d%d",&n,&m);
        for(i=1;i<=n;i++)
        {
            for(j=0;j<m;j++)
            {
                scanf("%s",&map);//这样处理可以解决的空格,换行的问题,都可以不管。
                a[i][j]=map[0];//再将所值赋给a[i][j]。
            }
        }
        sum=get_are();
        printf("%d\n",sum*3);
      /*  if(t!=0)
            printf("\n\n");*/
    }
    return 0;
}


Guess you like

Origin blog.csdn.net/u010200793/article/details/16119603