Code Forces 22B Bargaining Table
2 seconds
256 megabytes
standard input
standard output
Bob wants to put a new bargaining table in his office. To do so he measured the office room thoroughly and drew its plan: Bob's office room is a rectangular room n × m meters.
Each square meter of the room is either occupied by some furniture, or free. A bargaining table is rectangular, and should be placed so, that its sides are parallel to the office walls. Bob doesn't want to change or rearrange anything, that's why all the squares
that will be occupied by the table should be initially free. Bob wants the new table to sit as many people as possible, thus its perimeter should be maximal. Help Bob find out the maximum possible perimeter of a bargaining table for his office.
The first line contains 2 space-separated numbers n and m (1 ≤ n, m ≤ 25)
— the office room dimensions. Then there follow n lines withm characters
0 or 1 each. 0 stands for a free square meter of the office room. 1 stands for an occupied square meter. It's guaranteed that at least one square meter in the room is free.
Output one number — the maximum possible perimeter of a bargaining table for Bob's office room.
3 3
000
010
000
8
5 4
1100
0000
0000
0000
0000
16
暴力
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
#include <math.h>
#include <stdio.h> using namespace std;
int n,m;
char a[30][30];
int main()
{
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
scanf("%s",a[i]+1); bool tag=true;
int ans=0;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
if(a[i][j]=='1')
continue;
//cout<<a[i][j]<<endl;
for(int l=1;l+i-1<=n;l++)
{
for(int r=1;r+j-1<=m;r++)
{
tag=true;
for(int k=i;k<=i+l-1;k++)
{
for(int p=j;p<=r+j-1;p++)
{
if(a[k][p]=='1')
{
tag=false;break;
}
}
if(!tag)
break;
} if(tag)
ans=max(ans,(l+r)*2);
} }
}
}
printf("%d\n",ans);
return 0; }
Code Forces 22B Bargaining Table的更多相关文章
- CodeForces 22B Bargaining Table 简单DP
题目很好理解,问你的是在所给的图中周长最长的矩形是多长嗯用坐标(x1, y1, x2, y2)表示一个矩形,暴力图中所有矩形易得递推式:(x1, y1, x2, y2)为矩形的充要条件为: (x1, ...
- Code Forces 650 C Table Compression(并查集)
C. Table Compression time limit per test4 seconds memory limit per test256 megabytes inputstandard i ...
- CF 22B. Bargaining Table
水题.好久没有写过优化搜索题了. #include <cstdio> #include <cstring> #include <iostream> #include ...
- Codeforces 22B Bargaining Table
http://www.codeforces.com/problemset/problem/22/B 题意:求出n*m的方格图中全是0的矩阵的最大周长 思路:枚举 #include<cstdio& ...
- Bargaining Table
Bargaining Table time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...
- 思维题--code forces round# 551 div.2
思维题--code forces round# 551 div.2 题目 D. Serval and Rooted Tree time limit per test 2 seconds memory ...
- Inheritance with EF Code First: Part 3 – Table per Concrete Type (TPC)
Inheritance with EF Code First: Part 3 – Table per Concrete Type (TPC) This is the third (and last) ...
- Inheritance with EF Code First: Part 1 – Table per Hierarchy (TPH)
以下三篇文章是Entity Framework Code-First系列中第七回:Entity Framework Code-First(7):Inheritance Strategy 提到的三篇.这 ...
- 暴力/DP Codeforces Beta Round #22 (Div. 2 Only) B. Bargaining Table
题目传送门 /* 题意:求最大矩形(全0)的面积 暴力/dp:每对一个0查看它左下的最大矩形面积,更新ans 注意:是字符串,没用空格,好事多磨,WA了多少次才发现:( 详细解释:http://www ...
随机推荐
- mysql基础知识详解
分享一些mysql数据库的基础知识. 1.每个客户端连接都会从服务器进程中分到一个属于它的线程.而该连接的相应查询都都会通过该线程处理.2.服务器会缓存线程.因此并不会为每个新连接创建或者销毁线程.3 ...
- 如何生成项目的chm文档
如何生成项目的chm文档 2014-11-30 Generate .chm based documentation of your project using SandCastle tool
- 0071 CentOS_Tomcat访问文件名包含中文的文件出现404错误
访问CentOS+Tomcat下的,文件名包含中文的文件出现404错误 修改:apache-tomcat-7.0.78/conf/server.xml <Connector port=" ...
- What is purpose of @ConditionalOnProperty annotation?
http://stackoverflow.com/questions/26394778/what-is-purpose-of-conditionalonproperty-annotation **** ...
- rpc 理解
RPC=Remote Produce Call 是一种技术的概念名词. HTTP是一种协议,RPC可以通过HTTP来实现,也可以通过Socket自己实现一套协议来实现. rpc是一种概念,http也是 ...
- [接口]mmc/eMMC/SD-card
转自:http://blog.csdn.net/yazhouren/article/details/46643321 MMC(multiMedia card)是一种通信协议,支持两种模式SPI和MMC ...
- MyBatis Geneator详解<转>
MyBatis Geneator中文文档地址: http://generator.sturgeon.mopaas.com/ 该中文文档由于尽可能和原文内容一致,所以有些地方如果不熟悉,看中文版的文档的 ...
- Libgdx window add alpha action change the background actor alpha
现象: Stage中包括一个Window,一个Actor,Window中加入alpha action后,Actor也随之消失:Actor加入alpha action后,不起作用. 解决: 重写draw ...
- [android] android 获取网络连接信息
效果图: 工具类 /** * 获取网络连接信息 * * 根据NetworkInfo可以知道有很多的连接方式和信息 * * ① 当没有任何可用网络的时候,networkinfo为null 判断netw ...
- 逻辑表+session