最大正方形 (Standard IO)
来源:互联网 发布:数码合成软件nuke 编辑:程序博客网 时间:2024/05/13 16:26
Description
给一个N*N的01矩阵, 求一个面积最大的全为1的正方形子矩阵. 输出它的面积.
Input
输入文件square.in的第一行包含一个正整数N.
接下来N行, 每行N个数, 保证不是0就是1. 每行相邻两个数之间没有空格.
Output
输出文件为square.out,仅包含一个整数表示最大的全1子正方形矩阵的面积。
题解
五个字,优美的暴力。
代码
var n,ans:longint; f:array [0..1001,0..1001] of integer; a:array [0..1001,0..1001] of char;procedure init;var i,j:longint;begin readln(n); for i:=1 to n do begin for j:=1 to n do read(a[i,j]); readln; end; for i:=0 to n+1 do begin a[0,i]:='0'; a[n+1,i]:='0'; end; for i:=0 to n+1 do begin a[i,0]:='0'; a[i,n+1]:='0'; end; ans:=0;end;procedure main;var i,j,x,min:longint;begin fillchar(f,sizeof(f),0); for i:=1 to n do for j:=1 to n do if (a[i,j]='1') then if (a[i-1,j]='0') then f[i,j]:=1 else f[i,j]:=f[i-1,j]+1; for i:=1 to n do for j:=1 to n do if a[i,j]='1' then begin x:=j; min:=maxlongint; while a[i,x]='1' do begin if f[i,x]<min then min:=f[i,x]; if ((x-j+1)*min>ans) and ((x-j+1)=min) then ans:=(x-j+1)*min; inc(x); end; end; write(ans);end;begin init; main;end.
1 0
- 最大正方形 (Standard IO)
- 2548. 【NOIP2011模拟9.4】最大正方形 (Standard IO)
- 最小最大和 (Standard IO)
- 最小最大和 (Standard IO)
- 最大正方形
- 最大正方形
- 最大正方形
- 最大正方形
- 最大正方形
- 最大正方形
- 最大正方形
- 最大正方形 (Largest Square)
- 最大子正方形
- FZU 2056 最大正方形
- 找最大的正方形
- FZU 2056 最大正方形
- 01矩阵最大正方形
- 洛谷1387 最大正方形
- Codeforces Round #364 vp
- C++笔记(一):概念
- 刚刚犯了个错误,关于div定位的。
- 孙子兵法与企业经营3
- Hibernate 缓存机制
- 最大正方形 (Standard IO)
- SparkのRDD
- 交叉排序
- 关于对象原型链的理解
- Ubuntu下运行Shell脚本时显示“declare not found”的问题
- UVA 11059 Maximum Product
- 什么叫做SQL注入式攻击,如何防范?
- emplace_back减少内存拷贝和移动
- POJ 2488 A Knight's Journey