这道题下面这么写就够了(n<=100)暴力,枚举

#include<bits/stdc++.h>
#define ULL unsigned long long
#define MAXN 100+5
#define f(i,j,n) for(register int i=j;i<=n;i++)
using namespace std;
ULL T,a[MAXN][MAXN],n,m;
int q(int i,int j,int k,int l) {
f(p,i,j)
f(q,k,l)
if(a[p][q]==) return ;
return min(j-i+,l-k+);
}
void solve(int T) {
int ans=;
while(T--) {
memset(a,,sizeof(a));
cin>>n>>m;
f(i,,n)
f(j,,m) {
int x;
cin>>x;
a[i][j]=x;
}
f(i,,n)
f(j,i,n)
f(k,,m)
f(l,k,m)
ans=max(ans,q(i,j,k,l));
cout<<ans<<endl;
}
}
int main() {
solve();
return ;
}

然后如果说要提升的话(n<=1000) 二维前缀和

#include<iostream>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<algorithm>
using namespace std;
int n,m,map[][];
int sum[][];
void pre(){
for(int i=;i<=n;i++)
for(int j=;j<=m;j++)
sum[i][j]=sum[i-][j]+sum[i][j-]-sum[i-][j-]+map[i][j];
}
int main(){
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++)
for(int j=;j<=m;j++)
scanf("%d",&map[i][j]);
pre();
int ans=-;
for(int i=;i<=n;i++)
for(int j=;j<=m;j++)
for(int l=;l<=min(n,m);l++){
int rx=i+l-,ry=j+l-;
if(i-+l>n||j-+l>m||sum[rx][ry]-sum[rx][j-]-sum[i-][ry]+sum[i-][j-]!=l*l) break;
if(ans<l) ans=l;
}
printf("%d",ans);
return ;
}

然后在提升->(n<=5000)动态规划 DP

#include<bits/stdc++.h>
using namespace std;
int a[][],f[][],ans;
int main()
{
int n,m;
cin>>n>>m;
for(int i=;i<=n;i++)
{
for(int j=;j<=m;j++)
{
cin>>a[i][j];
if(a[i][j]==) f[i][j]=min(min( f[i][j-],f[i-][j]),f[i-][j-])+;
{
ans=max(ans,f[i][j]);
}
}
}
cout<<ans;
return ;
}

最大正方形 同luogu1387的更多相关文章

  1. luogu1387 最大正方形

    P1387 最大正方形 正方形O(n) 题目描述 在一个n*m的只包含0和1的矩阵里找出一个不包含0的最大正方形,输出边长. 输入输出格式 输入格式: 输入文件第一行为两个整数n,m(1<=n, ...

  2. [LeetCode] Matchsticks to Square 火柴棍组成正方形

    Remember the story of Little Match Girl? By now, you know exactly what matchsticks the little match ...

  3. [LeetCode] Maximal Square 最大正方形

    Given a 2D binary matrix filled with 0's and 1's, find the largest square containing all 1's and ret ...

  4. 【纯css】左图右文列表,左图外框宽度占一定百分比的正方形,右上下固定,右中自动响应高度。支持不规则图片。

    查看演示 <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF- ...

  5. BZOJ1047: [HAOI2007]理想的正方形 [单调队列]

    1047: [HAOI2007]理想的正方形 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 2857  Solved: 1560[Submit][St ...

  6. 洛谷 P1387 最大正方形 Label:奇怪的解法

    题目描述 在一个n*m的只包含0和1的矩阵里找出一个不包含0的最大正方形,输出边长. 输入输出格式 输入格式: 输入文件第一行为两个整数n,m(1<=n,m<=100),接下来n行,每行m ...

  7. H5一行显示两个正方形

    1)有时候一些图片会是正方形或者长方形,对于这样的图片一般都是居中显示到正方体内,代码如下:  .exhibition_list img{width:100%;position: relative;t ...

  8. 求解最大正方形面积 — leetcode 221. Maximal Square

    本来也想像园友一样,写一篇总结告别 2015,或者说告别即将过去的羊年,但是过去一年发生的事情,实在是出乎平常人的想象,也不具有代表性,于是计划在今年 6 月份写一篇 "半年总结" ...

  9. for 循环 正方形

    <?php//================================正方形//for($q = 1; $q <= 5; $q ++ ){//    for($z =1; $z & ...

随机推荐

  1. * screen recording on Ubuntu

    - byzanz- kazam-recordmydesktophttps://www.ubuntupit.com/15-best-linux-screen-recorder-and-how-to-in ...

  2. MySQL Connector/Python 接口 (二)

    连接数据库 本文参见这里,示例如何连接MySQL 数据库. import mysql.connector from mysql.connector import errorcode # 连接数据库需要 ...

  3. Tyvj1139 向远方奔跑(APIO 2009 抢掠计划)

    描述     在唐山一中,吃饭是一件很令人头疼的事情,因为你不可能每次都站在队伍前面买饭,所以,你最需要做的一件事就是——跑饭.而跑饭的道路是无比艰难的,因为路是单向的(你要非说成是双向的我也没法,前 ...

  4. Crashing Robots POJ 2632 简单模拟

    Description In a modernized warehouse, robots are used to fetch the goods. Careful planning is neede ...

  5. T1075 明明的随机数 codevs

    http://codevs.cn/problem/1075/ 时间限制: 1 s  空间限制: 128000 KB  题目等级 : 白银 Silver 题目描述 Description 明明想在学校中 ...

  6. 洛谷 P1993 小K的农场

    P1993 小K的农场 题目描述 小K在MC里面建立很多很多的农场,总共n个,以至于他自己都忘记了每个农场中种植作物的具体数量了,他只记得一些含糊的信息(共m个),以下列三种形式描述: 农场a比农场b ...

  7. - > 贪心基础入门讲解三——活动安排问题二

    有若干个活动,第i个开始时间和结束时间是[Si,fi),活动之间不能交叠,要把活动都安排完,至少需要几个教室?   分析:能否按照之一问题的解法,每个教室安排尽可能多的活动,即按结束时间排序,再贪心选 ...

  8. MyBatis3-SqlSessionDaoSupport的使用

    以下内容引用自http://www.yihaomen.com/article/java/336.htm: 在MyBatis3中这个Mapper接口貌似充当了以前在iBatis2中的DAO层的作用.但事 ...

  9. MyBatis3-示例工程

    一.准备工作: 0.新建QuitStart类型POM项目(即Application),Java Build Path为JDK1.8,Java Compiler为1.8,MySQL为5.5.38,数据库 ...

  10. heap实现

    //STL提供的是Max heap,使用vector作为底部容器 //push_heap算法:首先将元素放到堆所对应的数组的末端,然后从该节点开始向上调整, //若当前结点键值比父结点大,则兑换位置, ...