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. cookie、session、localstorage

    最早的Cookies问题主要就是太小,大概也就4KB的样子,而且IE6只支持每个域名20个cookies,太少了.优势就是大家都支持,而且支持得还蛮好.cookie的内容主要包括:名字,值,过期时间, ...

  2. TensorFlow中get_variable共享变量调用

    import tensorflow as tf with tf.variable_scope('v_scope',reuse=True) as scope1: Weights1 = tf.get_va ...

  3. Windows 提权对照表 精确到sp版本号

    https://www.securitysift.com/download/MS_privesc_and_exploits_table.csv

  4. peewee外键性能问题

    # 转载自:https://www.cnblogs.com/miaojiyao/articles/5217757.html 下面讨论一下用peewee的些许提高性能的方法. 避免N+1查询 N+1查询 ...

  5. xshell+xming连接服务器虚拟机启动mininet网络

    困于vnc连实验室的服务器虚拟机,一直出现页面不稳定的情况,然后本机虚拟机又带不起来,今天跟学弟交流,知道了ssh连接服务器的办法,心情好晴朗! xshell下载和安装,xshell使用 xshell ...

  6. STL之顺序容器 deque 动态数组

    deque是一个动态数组,deque与vector非常类似,vector是一个单向开口的连续线性空间,deque则是双向开口的连续线性空间.两者唯一的区别是deque可以在数组的开头和末尾插入和删除数 ...

  7. HA集群

    //硬件准备: .两个机器,相同系统 .网卡ip为:aming 192.168.11.24 aming1 192.168.11.23 //实验准备: . hostname : aming , amin ...

  8. 使用JMX工具远程监控tomcat配置

    使用JMX工具远程监控tomcat,在tomcat启动时添加配置参数: -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.po ...

  9. [译]怎样用HTML5 Canvas制作一个简单的游戏

    这是我翻译自LostDecadeGames主页的一篇文章,原文地址:How To Make A Simple HTML5 Canvas Game. 下面是正文: 自从我制作了一些HTML5游戏(例如C ...

  10. Pygame-依葫芦画瓢之兔獾大战

    Pygame-依葫芦画瓢之兔獾大战 前几天看到国外一个12岁的孩子写的兔獾大战游戏,心生敬佩,想当年我还是12岁的时候还不知电脑为何物,连小霸王都未曾玩过.自己也未曾想去搞游戏开发,纯属自娱自乐.在此 ...