bzoj 4506: [Usaco2016 Jan]Fort Moo

4506: [Usaco2016 Jan]Fort Moo

Description

Bessie is building a fort with her friend Elsie. Like any good fort, this one needs to start with a sturdy frame. Bessie wants to build a frame in the shape of a one-meter-wide rectangular outline, atop which she will build the fort.

Bessie has already chosen a site on which to build the fort -- a piece of land measuring NN meters by MM meters (1< = N,M< = 2001< = N,M< = 200). Unfortunately, the site has some swampy areas that cannot be used to support the frame. Please help Bessie determine the largest area she can cover with her fort (the area of the rectangle supported by the frame), such that the frame avoids sitting on any of the swampy areas.

Input

Line 1 contains integers N and M.

The next N lines each contain M characters, forming a grid describing the site. A character of ‘.‘ represents normal grass, while ‘X‘ represents a swampy spot.

Output

A single integer representing the maximum area that Bessie can cover with her fort.

Sample Input

5 6
......
..X..X
X..X..
......
..X...

Sample Output

16
In the example, the placement of the optimal frame is indicated by ‘f‘s below:
.ffff.
.fX.fX
Xf.Xf.
.ffff.
..X...

题解:

题目大意是找到一个最大的矩形使得矩形的外框均在不在沼泽上。

o(n4)的暴力我就不说了,也许会卡过。

讲一讲n3吧,我们只需枚举矩形的上下边界,然后用n的时间扫一遍。

#include<stdio.h>
#include<iostream>
using namespace std;
const int N=205;
char a[N][N];
int n,m,i,j,k,x,y,ans,b[N][N];
int main()
{
    scanf("%d%d",&n,&m);
    for(i=1;i<=n;i++)
        scanf("%s",a[i]+1);
    for(j=1;j<=m;j++)
     for(i=1;i<=n;i++)
     if(a[i][j]==‘X‘) b[i][j]=b[i-1][j]+1;else b[i][j]=b[i-1][j];
    for(i=1;i<=n;i++)
     for(j=i;j<=n;j++)
    {
        x=0;y=0;
        for(k=1;k<=m;k++)
            if(b[j][k]-b[i-1][k]==0)
        {
            x=max(x,k);
            y=x;
            while(x<m&&a[i][x+1]==‘.‘&&a[j][x+1]==‘.‘)
            {
                x++;
                if(b[j][x]-b[i-1][x]==0) y=x;
            }
            ans=max(ans,(j-i+1)*(y-k+1));
        }
    }
    cout<<ans;
    return 0;
}
时间: 2024-11-08 04:05:24

bzoj 4506: [Usaco2016 Jan]Fort Moo的相关文章

[BZOJ4506] [Usaco2016 Jan]Fort Moo(DP?)

传送门 总之可以先预处理出来每个位置最多往上延伸多少 枚举两行,看看夹在这两行中间的列最大能构成多大的矩形 可以看出,必须得在一个两行都没有X的区间才有可能构成最大的答案 那么可以把这些区间处理出来,在看看这些区间中的点最左边和最右边的能从下面那一行向上延伸到上面那一行的点,更新ans即可 #include <cstdio> #define N 201 #define max(x, y) ((x) > (y) ? (x) : (y)) int n, m, ans, p; int h[N]

BZOJ 4576: [Usaco2016 Open]262144

Description 一个序列,每次可以将两个相同的数合成一个数,价值+1,求最后最大价值 \(n \leqslant 262144\) Sol DP. 这道题是 BZOJ 4580: [Usaco2016 Open]248 加强版. 做248的那个区间DP其实很多方案都是0,而且一个区间中只有一个合法的数字. 然后就是 一个区间合成一个数的方案的这个数字是固定的. \(f[i][j]\) 表示以 \(i\) 结尾是否能合成 \(j\),同时记录一下转移位置,每次向前找前一个指针就可以了. 复

bzoj4509【Usaco2016 Jan】Angry Cows

4509: [Usaco2016 Jan]Angry Cows Time Limit: 10 Sec  Memory Limit: 128 MB Submit: 83  Solved: 38 [Submit][Status][Discuss] Description Bessie the cow has designed what she thinks will be the next big hit video game: "Angry Cows". The premise, whi

bzoj4510: [Usaco2016 Jan]Radio Contact

bzoj4510: [Usaco2016 Jan]Radio Contact Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 21  Solved: 17[Submit][Status][Discuss] Description Farmer John has lost his favorite cow bell, and Bessie the cow has agreed to help him find it! They both fan ou

BZOJ 1679 [Usaco2005 Jan]Moo Volume 牛的呼声

解法1: N^2的暴力程序,卡卡常数就过了. #include <cstdio> #include <algorithm> #include <cmath> int n; int a[10005]; long long tot; inline bool Read(int &ret){ char c; int flag = 1; if(c=getchar(),c==EOF) return 0; while(c!='-' && (c<'0'||

[BZOJ] 1614: [Usaco2007 Jan]Telephone Lines架设电话线

1614: [Usaco2007 Jan]Telephone Lines架设电话线 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 1806  Solved: 773[Submit][Status][Discuss] Description Farmer John打算将电话线引到自己的农场,但电信公司并不打算为他提供免费服务.于是,FJ必须为此向电信公司支付一定的费用. FJ的农场周围分布着N(1 <= N <= 1,000)根按1..N顺次编号的废

bzoj 1699: [Usaco2007 Jan]Balanced Lineup排队 分块

1699: [Usaco2007 Jan]Balanced Lineup排队 Time Limit: 5 Sec  Memory Limit: 64 MB Description 每天,农夫 John 的N(1 <= N <= 50,000)头牛总是按同一序列排队. 有一天, John 决定让一些牛们玩一场飞盘比赛. 他准备找一群在对列中为置连续的牛来进行比赛. 但是为了避免水平悬殊,牛的身高不应该相差太大. John 准备了Q (1 <= Q <= 180,000) 个可能的牛的

BZOJ 3887[Usaco2015 Jan]Grass Cownoisseur

题面: 3887: [Usaco2015 Jan]Grass Cownoisseur Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 237  Solved: 130[Submit][Status][Discuss] Description In an effort to better manage the grazing patterns of his cows, Farmer John has installed one-way cow pat

BZOJ 4742: [Usaco2016 Dec]Team Building

4742: [Usaco2016 Dec]Team Building Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 21  Solved: 16[Submit][Status][Discuss] Description Every year, Farmer John brings his NN cows to compete for "best in show" at the state fair. His arch -rival, F