最大正方形 同luogu1387
这道题下面这么写就够了(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的更多相关文章
- luogu1387 最大正方形
P1387 最大正方形 正方形O(n) 题目描述 在一个n*m的只包含0和1的矩阵里找出一个不包含0的最大正方形,输出边长. 输入输出格式 输入格式: 输入文件第一行为两个整数n,m(1<=n, ...
- [LeetCode] Matchsticks to Square 火柴棍组成正方形
Remember the story of Little Match Girl? By now, you know exactly what matchsticks the little match ...
- [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 ...
- 【纯css】左图右文列表,左图外框宽度占一定百分比的正方形,右上下固定,右中自动响应高度。支持不规则图片。
查看演示 <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF- ...
- BZOJ1047: [HAOI2007]理想的正方形 [单调队列]
1047: [HAOI2007]理想的正方形 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 2857 Solved: 1560[Submit][St ...
- 洛谷 P1387 最大正方形 Label:奇怪的解法
题目描述 在一个n*m的只包含0和1的矩阵里找出一个不包含0的最大正方形,输出边长. 输入输出格式 输入格式: 输入文件第一行为两个整数n,m(1<=n,m<=100),接下来n行,每行m ...
- H5一行显示两个正方形
1)有时候一些图片会是正方形或者长方形,对于这样的图片一般都是居中显示到正方体内,代码如下: .exhibition_list img{width:100%;position: relative;t ...
- 求解最大正方形面积 — leetcode 221. Maximal Square
本来也想像园友一样,写一篇总结告别 2015,或者说告别即将过去的羊年,但是过去一年发生的事情,实在是出乎平常人的想象,也不具有代表性,于是计划在今年 6 月份写一篇 "半年总结" ...
- for 循环 正方形
<?php//================================正方形//for($q = 1; $q <= 5; $q ++ ){// for($z =1; $z & ...
随机推荐
- CCF201503-2 数字排序 java(100分)
试题编号: 201503-2 试题名称: 数字排序 时间限制: 1.0s 内存限制: 256.0MB 问题描述: 问题描述 给定n个整数,请统计出每个整数出现的次数,按出现次数从多到少的顺序输出. 输 ...
- 51nod 1096 距离之和最小 1108 距离之和最小 V2
[题解] 很显然在一条坐标轴上到各个点距离之和最小的点就是它们的中位数.怎么证明呢?我们假设现在找的某个点x左边有a个点,右边有b个点(a>b).我们把x向左移动d个单位,并保证x左边依然有a个 ...
- 1. Jenkins 入门使用
1. 下载jenkins https://pkg.jenkins.io/redhat-stable/ sudo wget -O /etc/yum.repos.d/jenkins.repo https: ...
- BZOJ 3894 Luogu P4313 文理分科 (最小割)
题目链接: (bzoj) https://www.lydsy.com/JudgeOnline/problem.php?id=3894 (luogu) https://www.luogu.org/pro ...
- vue 刷新当前页面的时候重新调用新的cookie
data() { return{ AdminToken: this.getCookie('token'), } }, updated() { //刷新当前页面的时候重新调用新的cookie this. ...
- linux 卸载php mysql apache
卸载Mysql 1.查找以前是否装有mysql 命令:rpm -qa|grep -i mysql 可以看到mysql的包: mysql-3.23.58-9php-mysql-4.3.4-11mod_a ...
- PayPal加密证书.pem的生成
How do I create a public certificate for use with PayPal Encrypted Website Payments? Before you ca ...
- JAVA高速开发平台 - 开源 免费 - JEECG
JEECG 微云高速开发平台 当前最新版本号: 3.6.2(公布日期:20160315) 下载地址:http://git.oschina.net/jeecg/jeecg 前言: 随着 WEB UI 框 ...
- iOS 设置启动页面 时间
[NSThread sleepForTimeInterval:3.0]; 时间越大 ,启动页面停留的时间越长 iOS 8之后,,创建项目自带的有 LaunchScreen.xib 可直接用
- LeetCode 438. Find All Anagrams in a String (在字符串中找到所有的变位词)
Given a string s and a non-empty string p, find all the start indices of p's anagrams in s. Strings ...