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=;
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=;i<=n;i++)
scanf("%s",a[i]+);
for(j=;j<=m;j++)
for(i=;i<=n;i++)
if(a[i][j]=='X') b[i][j]=b[i-][j]+;else b[i][j]=b[i-][j];
for(i=;i<=n;i++)
for(j=i;j<=n;j++)
{
x=;y=;
for(k=;k<=m;k++)
if(b[j][k]-b[i-][k]==)
{
x=max(x,k);
y=x;
while(x<m&&a[i][x+]=='.'&&a[j][x+]=='.')
{
x++;
if(b[j][x]-b[i-][x]==) y=x;
}
ans=max(ans,(j-i+)*(y-k+));
}
}
cout<<ans;
return ;
}

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

  1. bzoj4506: [Usaco2016 Jan]Fort Moo(暴力)

    4506: [Usaco2016 Jan]Fort Moo Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 145  Solved: 104[Submi ...

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

    传送门 总之可以先预处理出来每个位置最多往上延伸多少 枚举两行,看看夹在这两行中间的列最大能构成多大的矩形 可以看出,必须得在一个两行都没有X的区间才有可能构成最大的答案 那么可以把这些区间处理出来, ...

  3. BZOJ 4576: [Usaco2016 Open]262144

    Description 一个序列,每次可以将两个相同的数合成一个数,价值+1,求最后最大价值 \(n \leqslant 262144\) Sol DP. 这道题是 BZOJ 4580: [Usaco ...

  4. DP【洛谷P3135】[USACO16JAN]堡哞Fort Moo

    [洛谷P3135][USACO16JAN]堡哞Fort Moo Bessie和她的朋友Elsie正在建筑一个堡垒,与任何一个好的堡垒一样,这个需要一个强固的框架.Bessie想造一个轮廓是1m宽的空心 ...

  5. [bzoj 3048] [Usaco2013 Jan]Cow Lineup

    [bzoj 3048] [Usaco2013 Jan]Cow Lineup Description 给你一个长度为n(1<=n<=100,000)的自然数数列,其中每一个数都小于等于10亿 ...

  6. bzoj4512[Usaco2016 Jan] Build Gates

    bzoj4512[Usaco2016 Jan] Build Gates 题意: 某人从农场的(0,0)出发,沿边界到处乱走,走过的地方会留下栅栏,等走完后问要在多少个栅栏上开门才能使整个农场连通,最多 ...

  7. BZOJ 1679: [Usaco2005 Jan]Moo Volume 牛的呼声( )

    一开始直接 O( n² ) 暴力..结果就 A 了... USACO 数据是有多弱 = = 先sort , 然后自己再YY一下就能想出来...具体看code --------------------- ...

  8. bzoj 1679: [Usaco2005 Jan]Moo Volume 牛的呼声【枚举】

    直接枚举两两牛之间的距离即可 #include<iostream> #include<cstdio> #include<algorithm> using names ...

  9. BZOJ 4742: [Usaco2016 Dec]Team Building

    4742: [Usaco2016 Dec]Team Building Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 21  Solved: 16[Su ...

随机推荐

  1. adb操作指令大全

    adb是什么?:adb的全称为Android Debug Bridge,就是起到调试桥的作用.通过adb我们可以在Eclipse中方面通过DDMS来调试android程序,说白了就是debug工具.a ...

  2. rabbitmq之配置文件详解(二)

    前言 前面介绍了erlang环境的安装和rabbitmq环境安装,接下来对rabbitmq详细配置: 设置配置文件 rabbitmq的系统配置文件一般是rabbitmq.conf,可以登录后台查看它的 ...

  3. Linux网络编程之套接字基础

    1.套接字的基本结构 struct sockaddr 这个结构用来存储套接字地址. 数据定义: struct sockaddr { unsigned short sa_family; /* addre ...

  4. ERROR: do not initialise statics to false

    Question about git commit rule I git commit a patch, The patch has a "static int xxxxxxxxxxxxxx ...

  5. linux dpm机制分析(下)【转】

    转自:http://blog.csdn.net/lixiaojie1012/article/details/23707901 1      设备注册到dpm_list路径 (Platform_devi ...

  6. 【LOJ2254】SNOI2017一个简单的询问

    莫队,每次询问的是两个区间,就把区间拆开,分开来算就好了. 借鉴了rank1大佬的玄学排询问的姿势. #include<bits/stdc++.h> #define N 50010 typ ...

  7. UVALive 7040 Color

    题目链接:LA-7040 题意为用m种颜色给n个格子染色.问正好使用k种颜色的方案有多少. 首先很容易想到的是\( k * (k-1)^{n-1}\),这个算出来的是使用小于等于k种颜色给n个方格染色 ...

  8. C 基础框架开发

    引言 有的人真的是天命所归 延安时期炸弹 投到他院子都 没炸. 有些事无法改变 是命! 我们也快'老'了, 常回家看看. 前言 扯淡结束了,今天分享的可能有点多,都很简单,但是糅合在一起就是有点复杂. ...

  9. Tomcat+Apache 负载均衡

    1.JDK1.8和Tomcat7.0不兼容,支持Tomcat8.0. 集群架构图: 2.负载均衡:负载的基础是集群,集群就是一组连在一起的计算机,从外部看它是一个系统,各节点可以是不同的操作系统或不同 ...

  10. 20180104 wdcp中的mysql重启不成功

    1.重启不成功是由于/www/wdlinux/mysql-5.5.54/data 中的ib_logfile0.ib_logfile1 和ibdata1的文件存在,可用netstat -lnpt查看当前 ...