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

  1. 4 5
  2. 0 1 0 1 1
  3. 1 1 1 1 1
  4. 0 1 1 1 0
  5. 1 1 1 1 1
  6. 3 4
  7. 1 1 1 1
  8. 1 1 1 1
  9. 1 1 1 1
  10. 6 6
  11. 0 0 0 0 0 0
  12. 0 0 0 0 0 0
  13. 0 0 0 0 0 0
  14. 0 0 0 0 0 0
  15. 0 0 0 0 0 0
  16. 0 0 0 0 0 0
  17. 0 0

Sample Output

  1. 3
  2. 3
  3. 0
  1. #include <cstdio>
  2. #include <cmath>
  3. #include <cstring>
  4. #include <ctime>
  5. #include <iostream>
  6. #include <algorithm>
  7. #include <set>
  8. #include <vector>
  9. #include <sstream>
  10. #include <queue>
  11. #include <typeinfo>
  12. #include <fstream>
  13. typedef long long ll;
  14. using namespace std;
  15. //freopen("D.in","r",stdin);
  16. //freopen("D.out","w",stdout);
  17. #define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
  18. #define maxn 1010
  19. const int inf=0x7fffffff; //无限大
  20. int g[maxn][maxn];
  21. int main()
  22. {
  23. int m,n;
  24. while(cin>>n>>m)
  25. {
  26. if(m==&&n==)
  27. break;
  28. memset(g,,sizeof(g));
  29. for(int i=;i<n;i++)
  30. {
  31. for(int j=;j<m;j++)
  32. {
  33. cin>>g[i][j];
  34. }
  35. }
  36. int ans=;
  37. for(int i=;i<n;i++)
  38. {
  39. for(int j=;j<m;j++)
  40. {
  41. if(i==||j==)
  42. {
  43. ans=max(g[i][j],ans);
  44. continue;
  45. }
  46. if(g[i][j]==)
  47. continue;
  48. g[i][j]=min(g[i-][j],min(g[i][j-],g[i-][j-]))+;
  49. ans=max(g[i][j],ans);
  50. }
  51. }
  52.  
  53. cout<<ans<<endl;
  54. }
  55. return ;
  56. }

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. aarch64_n2

    nodejs-is-dotfile-1.0.2-2.fc26.noarch.rpm 2017-02-12 00:27 9.5K fedora Mirroring Project nodejs-is-e ...

  2. Python 使用 Redis 操作

    1.redis简介 redis是一款开源免费的高性能key-value数据库,redis特点: 支持更多的数据类型:字符串(String).列表(List).哈希(Map).数字(Int).集合(Se ...

  3. AngularJS中ng-class使用方法

    转自:https://blog.csdn.net/jumtre/article/details/50802136 其他博文ng-class使用方法:https://blog.csdn.net/sina ...

  4. python去除html空格

    如下面的 <td> 柳暗花溟</td> html里面的空格&nbsp,想直接用strip()函数去除是不可能的,必须显式的去掉\xa0 例如以上的就可以这样的方式去除空 ...

  5. webpack3学习笔记

    地址:https://segmentfault.com/a/1190000006843916 地址:https://www.chungold.com/my/course/32 地址:http://js ...

  6. android studio 解决avd启动问题 ----waiting for target device come online

    android studio 模拟器打不开,一直停留在第三方.waiting for target  device  come online 问题解决方法 方法1.Android Emulator 未 ...

  7. 读书笔记--C陷阱与缺陷(五)

    第五章 第五章干货也偏少,但是几个练习题还不错,写出来大家分享下: 1.当一个程序异常终止时,程序输出的最后几行常常会丢失,原因是什么? 我们能够采取怎么样的措施来解决这个问题? 答:因为异常终止的程 ...

  8. No.3 selenium学习之路之鼠标&键盘事件

    鼠标事件 from selenium.webdriver.common.action_chains import ActionChains contest_click()  右击 double_cli ...

  9. 【[SDOI2009]Bill的挑战】

    一看题解好像全是状压DP,那么我就来补充一个容斥写法吧 乍一看,好像是水题,枚举选哪k个串,然后判断 1,如果这k个串中至少两个串某位置确定且不相同,答案显然为02,如果这个位置只被有且仅有一个串确定 ...

  10. Unix IPC之Posix信号量实现生产者消费者

    采用多生产者,多消费者模型. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 /**  * 生产者  */ P(nempty); P(mutex); // 写入一个 ...