2548. 【NOIP2011模拟9.4】最大正方形 (StandardIO)
2016-08-13 19:16
375 查看
2548. 【NOIP2011模拟9.4】最大正方形 (StandardIO)
Description给一个N*N的01矩阵, 求一个面积最大的全为1的正方形子矩阵. 输出它的面积.
Input
输入文件square.in的第一行包含一个正整数N.
接下来N行, 每行N个数, 保证不是0就是1. 每行相邻两个数之间没有空格.
Output
输出文件为square.out,仅包含一个整数表示最大的全1子正方形矩阵的面积。
Sample Input
2
11
11
Sample Output
4
Hint
【数据规模和约定】
80%的数据中 N<=250;
100%的数据中 N <= 1000。
思路:
本题呢算简单的吧,我也不知道考的叫什么名字,反正就是一个矩阵先做前缀和,然后计算出每个边长的正方形,暴力枚举,然后用二分去枚举边
const
maxn=1000;
var
a:array [0..maxn+1,0..maxn+1] of longint;
s:array [1..maxn] of ansistring;
i,j,n,max:longint;
function find(x:longint):boolean;
var
i,j:longint;
begin
find:=false;
for i:=0 to n-x do
for j:=0 to n-x do
if (a[i+x,j+x]-a[i+x,j]-a[i,j+x]+a[i,j]=0) then exit(true);
exit(false);
end;
procedure sort(l,r:longint);
var
i,j,mid:longint;
begin
if r-l<=1 then
begin
if find(r) then writeln(r*r)
else
if find(l) then writeln(l*l)
else writeln(0);
halt;
end;
mid:=(l+r) div 2;
if find(mid) then
begin
sort(mid,r);
end else
sort(l,mid-1);
end;
begin
readln(n);
for i:=1 to n do
readln(s[i]);
for i:=1 to n do
for j:=1 to n do
if s[i,j]='0' then a[i,j]:=a[i-1,j]+a[i,j-1]-a[i-1,j-1]+1
else a[i,j]:=a[i-1,j]+a[i,j-1]-a[i-1,j-1];
sort(1,n);
end.
相关文章推荐
- jzoj 2548. 【NOIP2011模拟9.4】最大正方形
- 2548. 【NOIP2011模拟9.4】最大正方形 (Standard IO)
- 2549. 【NOIP2011模拟9.4】家庭作业 (StandardIO)
- 2557. 【NOIP2011模拟9.9】单词分类 (StandardIO)
- 2553. 【NOIP2011模拟9.7】射命丸文 (StandardIO)
- 2570. 【NOIP2011模拟9.17】数字生成游戏 (StandardIO)
- 2558. 【NOIP2011模拟9.9】过河问题 (StandardIO)
- 2559. 【NOIP2011模拟9.9】最短路 (StandardIO)
- 2541. 【NOIP2011模拟9.1】方格取数 (StandardIO)
- 2549. 【NOIP2011模拟9.4】家庭作业 (Standard IO)
- 2567. 【NOIP2011模拟9.17】电话时间 (StandardIO)
- 2542. 【NOIP2011模拟9.1】统计 (StandardIO)
- jzoj 2541. 【NOIP2011模拟9.1】方格取数
- 【NOIP2011模拟9.3】跳舞 (Standard IO)
- jzoj 2546. 【NOIP2011模拟9.3】遥控车
- JZOJ8.11(C组)【NOIP2011模拟9.1】方格取数 (Standard IO)
- {题解}[jzoj2563]【NOIP2011模拟9.15】区间运算
- 2556. 【NOIP2011模拟9.7】伊吹萃香 (Standard IO)
- Jzoj 2555. 【NOIP2011模拟9.7】雾雨魔理沙
- 【NOIP2011模拟9.15】区间运算