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 ...
随机推荐
- Struts2初学 Struts.xml详解二
A.使用继承实现设置全局视图 package节点中还可以设置全局的视图,如: <global-results> <result name="e ...
- Redis 学习笔记四 Mysql 与Redis的同步实践
一.测试环境在Ubuntu kylin 14.04 64bit 已经安装Mysql.Redis.php.lib_mysqludf_json.so.Gearman. 点击这里查看测试数据库及表参考 本文 ...
- apue编程之参考df代码写的一个简单的df命令的源代码
代码: #include <stdio.h> #include <mntent.h> #include <string.h> #include <sys/vf ...
- 拿与不拿的dfs
在n个物品中拿k个,使得花费恰好为m. 典型的dfs,对每一个物品,可以选择拿与不拿,然后在判断下一个物品. 失败的dfs: 代码没有保存,只重写一下dfs函数的关键部分: ;i<n;i++) ...
- 基于jQuery的图片异步加载和预加载实例
如今的网页中有很多图片,比如相册列表,那么如果一次性读取图片将会瞬间加重服务器的负担,所以我们用jQuery来实现图片的异步加载和预加载功能,这样在页面的可视范围内才会加载图片,当拖动页面至可视界面时 ...
- ExecuteNonQuery和ExecuteScalar的区别
ExecuteNonQuery 针对 Connection 执行 SQL 语句并返回受影响的行数. 返回值 受影响的行数. 备注 您可以使用 ExecuteNonQuery 来执行目录操作(例如查 ...
- Spider Studio 新版本 (20140225) - 设置菜单调整 / 提供JQueryContext布局相关的方法
这是年后的第一个新版本, 包含如下: 1. 先前去掉的浏览器设置功能又回来了! 说来惭愧, 去掉了这两个功能之后发现浏览经常会被JS错误打断, 很不方便, 于是乎又把它们给找回来了. :) 2. 为J ...
- 0810 smarty
1.Smarty简介(why,what) why:smarrty 将前端工程师和程序员的工作分开,让前端工程师完成前台页面的工作,程序员完成后台的业务逻辑.what模版引擎是用来将PHP代码和模版页组 ...
- 燕十八mysql笔记
mysql复习 一:复习前的准备 1:确认你已安装wamp 2:确认你已安装ecshop,并且ecshop的数据库名为shop 二 基础知识: 1.数据库的连接 mysql -u -p -h -u 用 ...
- 解决Maven项目 Missing artifact jdk.tools:jdk.tools:1.7的错误
因学习项目需要,在pom.xml添加hbase-client依赖的时候提示解决Maven工程中报 Missing artifact jdk.tools:jdk.tools:1.7的提示信息,之前遇到这 ...