hdu 1505 City Game(hdu1506的二维推广)

1.输入的时候数据的时候要注意

2.1506的二维推广

代码:

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

const int INF=1<<30;
int a[1005][1005];
int L[1005];
int R[1005];

int main()
{
    int t;
    int m,n;
    int ans;
    char s[10];
    scanf("%d",&t);
    memset(a,0,sizeof(a));
    while(t--)
    {
        scanf("%d%d",&m,&n);
        for(int i=1;i<=m;i++)
        {
            for(int j=1;j<=n;j++)
            {
                scanf("%s",s);
                if(s[0]=='F')
                    a[i][j]=1;
                else
                    a[i][j]=0;
            }
        }
        ans=-INF;
        for(int i=1;i<=m;i++)
        {
            for(int j=1;j<=n;j++)
            {
                if(a[i][j]==1)
                    a[i][j]+=a[i-1][j];
            }
            for(int j=1;j<=n;j++)
            {
                L[j]=j;
                while(L[j]>1&&a[i][L[j]-1]>=a[i][j])
                    L[j]=L[L[j]-1];
            }
            for(int j=n;j>=1;j--)
            {
                R[j]=j;
                while(R[j]<n&&a[i][R[j]+1]>=a[i][j])
                    R[j]=R[R[j]+1];
            }
            for(int j=1;j<=n;j++)
            {
                ans=max(ans,a[i][j]*(R[j]-L[j]+1));
            }
        }
        printf("%d\n",3*ans);
    }
    return 0;
}
时间: 2024-10-10 09:13:38

hdu 1505 City Game(hdu1506的二维推广)的相关文章

hdu 1505 City Game (hdu1506加强版)

# include <stdio.h> # include <algorithm> # include <string.h> # include <iostream> using namespace std; char a[1010][1010]; int dd[1010][1010];///宽度 int r[1010],l[1010]; int main() { int t,i,j,n,m,max1; while(~scanf("%d"

hdu 1823 Luck and Love ,二维线段树

Luck and Love Time Limit: 10000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 5282    Accepted Submission(s): 1324 Input 本题有多个测试数据,第一个数字M,表示接下来有连续的M个操作,当M=0时处理中止. 接下来是一个操作符C. 当操作符为'I'时,表示有一个MM报名,后面接着一个整数,H表示身

HDU 1505 City Game (hdu1506 dp二维加强版)

F - City Game Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 1505 Appoint description: Description Bob is a strategy game programming specialist. In his new city building game the gaming enviro

HDU 2888:Check Corners(二维RMQ)

http://acm.hdu.edu.cn/showproblem.php?pid=2888 题意:给出一个n*m的矩阵,还有q个询问,对于每个询问有一对(x1,y1)和(x2,y2),求这个子矩阵中的最大值,和判断四个角有没有等于这个最大值的. 思路:二维RMQ模板题.注意内存卡的挺紧的. 1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 #include <cmath> 5

HDU 1024 Max Sum Plus Plus(二维数组转化为一维数组)

Problem Description: Now I think you have got an AC in Ignatius.L's "Max Sum" problem. To be a brave ACMer, we always challenge ourselves to more difficult problems. Now you are faced with a more difficult problem. Given a consecutive number seq

HDU 5119 Happy Matt Friends(简单二维dp)

题意不再说了,就是一个二维的dp,维持取最大值是多少. Happy Matt Friends Time Limit: 6000/6000 MS (Java/Others)    Memory Limit: 510000/510000 K (Java/Others) Total Submission(s): 608    Accepted Submission(s): 229 Problem Description Matt has N friends. They are playing a ga

HDU 1832 Luck and Love (二维线段树)

Problem Description 世界上上最远的距离不是相隔天涯海角 而是我在你面前 可你却不知道我爱你 ―― 张小娴 前段日子,枫冰叶子给Wiskey做了个征婚启事,聘礼达到500万哦,天哪,可是天文数字了啊,不知多少MM蜂拥而至,顿时万人空巷,连扫地的大妈都来凑热闹来了.―_―||| 由于人数太多,Wiskey实在忙不过来,就把统计的事情全交给了枫冰叶子,自己跑回家休息去了.这可够枫冰叶子忙的了,他要处理的有两类事情,一是得接受MM的报名,二是要帮Wiskey查找符合要求的MM中缘分最

HDU 1505 City Game【DP】

题意:是二维的1506,即在1506的基础上,再加一个for循环,即从第一行到最后一行再扫一遍--- 自己写的时候,输入的方法不对---发现输不出结果,后来看了别人的[email protected][email protected]发现是将字母和空格当成一个字符串来输入的. #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace st

HDU 2642(树状数组模板二维)

Stars Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/65536 K (Java/Others) Total Submission(s): 1350    Accepted Submission(s): 554 Problem Description Yifenfei is a romantic guy and he likes to count the stars in the sky. To make the