E - Maximum Square

Time Limit:4500MS     Memory Limit:0KB     64bit IO Format:%lld & %llu

Description

Given an NxM matrix of all 1s and 0s, find the largest submatrix which is a square containing all 1s.

Input

There will be several test cases in the input. Each test case will begin with two integers, N and M(1N, M1, 000) indicating the number of rows and columns of the matrix. The next N lines will each contain M space-separated integers, guaranteed to be either 0 or 1. The input will end with a line with two 0s.

Output

For each test case, print a single integer, indicating the width (and height) of the largest square of all 1s, or 0 if there are no 1s. Print no extra spaces, and do not print any blank lines between answers.

Sample Input

4 5
0 1 0 1 1
1 1 1 1 1
0 1 1 1 0
1 1 1 1 1
3 4
1 1 1 1
1 1 1 1
1 1 1 1
6 6
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0

Sample Output

3
3
0
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 1010
const int inf=0x7fffffff; //无限大
int g[maxn][maxn];
int main()
{
int m,n;
while(cin>>n>>m)
{
if(m==&&n==)
break;
memset(g,,sizeof(g));
for(int i=;i<n;i++)
{
for(int j=;j<m;j++)
{
cin>>g[i][j];
}
}
int ans=;
for(int i=;i<n;i++)
{
for(int j=;j<m;j++)
{
if(i==||j==)
{
ans=max(g[i][j],ans);
continue;
}
if(g[i][j]==)
continue;
g[i][j]=min(g[i-][j],min(g[i][j-],g[i-][j-]))+;
ans=max(g[i][j],ans);
}
} cout<<ans<<endl;
}
return ;
}

UVALive 4867 Maximum Square 贪心的更多相关文章

  1. Codeforces Round #599 (Div. 2) A. Maximum Square 水题

    A. Maximum Square Ujan decided to make a new wooden roof for the house. He has

  2. UVAlive 2911 Maximum(贪心)

    Let x1, x2,..., xm be real numbers satisfying the following conditions: a) -xi ; b) x1 + x2 +...+ xm ...

  3. uvalive 2911 Maximum(贪心)

    题目连接:2911 - Maximum 题目大意:给出m, p, a, b,然后xi满足题目中的两个公式, 要求求的 xp1 + xp2 +...+ xpm 的最大值. 解题思路:可以将x1 + x2 ...

  4. 【CF1243A】Maximum Square【贪心】

    题意:给你n个长度为ai的木板,求最大能拼成的矩形为多大 题解:显然贪心每次选最大的进去拼,那么剧需要枚举矩形长度x,看最长的k个能够拼出长度为x的矩形即可 #include<iostream& ...

  5. Codeforces Round #599 (Div. 2) A. Maximum Square

    Ujan decided to make a new wooden roof for the house. He has nn rectangular planks numbered from 11  ...

  6. UVALive 4225 Prime Bases 贪心

    Prime Bases 题目连接: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&a ...

  7. UVALive 7464 Robots (贪心)

    Robots 题目链接: http://acm.hust.edu.cn/vjudge/contest/127401#problem/K Description http://7xjob4.com1.z ...

  8. uvalive 3971 - Assemble(二分搜索 + 贪心)

    题目连接:3971 - Assemble 题目大意:有若干个零件, 每个零件给出的信息有种类, 名称, 价格, 质量,  现在给出一个金额, 要求在这个金额范围内, 将每个种类零件都买一个, 并且尽量 ...

  9. CodeForces 276D – Little Girl and Maximum XOR 贪心

    整整10个月后第二次搞这个问题才搞懂........第一次还是太随意了. 解题思路: 经过打表可得规律答案要么是0 要么是2的N次 - 1 要得到最大的XOR值,其值一定是2的N次 - 1 即在 l ...

随机推荐

  1. accept系统调用

    /* * For accept, we attempt to create a new socket, set up the link * with the client, wake up the c ...

  2. Runtime - 消息发送原理

    Runtime - 消息发送原理. Objective-C运行时的核心就在于消息分派器objc_msgSend,消息分派器把选择器映射为函数指针,并调用被引用的函数. 要想理解objc_msgSend ...

  3. Python操作Excle

    python操作excel主要用到xlrd和xlwt这两个库,即xlrd是读excel,xlwt是写excel的库.可从这里下载https://pypi.python.org/pypi.下面分别记录p ...

  4. linux用户权限 -> 系统用户管理

    用户基本概述: Linux用户属于多用户操作系统,在windows中,可以创建多个用户,但不允许同一时间多个用户进行系统登陆,但是Linux可以同时支持多个用户同时登陆操作系统,登陆后互相之间并不影响 ...

  5. ExtJs对js基本语法扩展支持

    ExtJs对js基本语法扩展支持 本篇主要介绍一下ExtJs对JS基本语法的扩展支持,包括动态加载.类的封装等. 一.动态引用加载 ExtJs有庞大的类型库,很多类可能在当前的页面根本不会用到,我们可 ...

  6. javaweb 要学习的东西

    我学院课设是Javaweb程序,要用eclipse,tomcat,jbdc,和数据库 jbdc,是连接数据库的驱动,tomcat是一种类似于服务器的东西,现在买不起服务器,就用tomcat

  7. JAVA 转义字符串中的特殊字符

    package test; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Test { pu ...

  8. 使用 ResponseBodyAdvice 拦截Controller方法默认返回参数,统一处理返回值/响应体

    使用 @ControllerAdvice & ResponseBodyAdvice 拦截Controller方法默认返回参数,统一处理返回值/响应体 1.Controller代码 以下是Con ...

  9. linux 101 hacks 2date,grep,find

    感觉挨个按着作者来的太蠢了,我还是放自己觉得不错的东西把 用特定格式显示当前时间 以下的方法可以用各种不同的格式来显示当前时间: $ date Thu Jan :: PST $ date --date ...

  10. Decorator 装饰

    意图 动态地给一个对象添加一些额外的职责.就增加功能来说,Decorator模式相比生成子类更为灵活. 结构 Component:定义一个对象接口,可以给这些对象动态地添加职责:(纯虚函数) Conc ...