Codeforces 713D Animals and Puzzle
题意:一个n*m的01矩阵,Q个询问,每次询问一个矩形区域内,最大的全1正方形的边长是多少?
题解:dp[0][0][i][j]表示以(i, j)为右下角的正方形的最长边长。RMQ后,二分答案即可。
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
;
int x1, y1, x2, y2, n, m;
int a[N][N];
][][N][N];
int Log[N];
int ask(int x1, int y1, int x2, int y2){
], k2 = Log[y2-y1+];
<<k2)+]);
ans = max(ans, dp[k1][k2][x2-(<<k1)+][y1]);
ans = max(ans, dp[k1][k2][x2-(<<k1)+][y2-(<<k2)+]);
return ans;
}
bool test(int l){
//dp[0][x1][y1] dp[0][x2-x+1][y2-x+1]
, y1+l-, x2, y2);
return ret >= l;
}
void init(){
; i <= Log[n]; i++)
; x+(<<i)- <= n; x++)
; y <= m; y++)
dp[i][][x][y] = max(dp[i-][][x][y], dp[i-][][x+(<<i-)][y]);
; i <= Log[n]; i++)
; j <= Log[m]; j++)
; x+(<<i)- <= n; x++)
; y+(<<j)- <= m; y++)
dp[i][j][x][y] = max(dp[i][j-][x][y], dp[i][j-][x][y+(<<j-)]);
}
int main(){
; i < N; i++) Log[i] = Log[i>>]+;
scanf("%d%d", &n, &m);
; i <= n; i++)
; j <= m; j++){
scanf("%d", &a[i][j]);
) dp[][][i][j] = ;
else{
][][i-][j], dp[][][i][j-]);
dp[][][i][j] = len+a[i-len][j-len];
}
}
init();
int t; scanf("%d", &t);
while(t--){
scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
, R = min(x2-x1+, y2-y1+);
while(L < R){
>> ;
if( test(M) )
L = M;
else
R = M-;
}
printf("%d\n", L);
}
;
}
Codeforces 713D Animals and Puzzle的更多相关文章
- Codeforces 713D Animals and Puzzle(二维ST表+二分答案)
题目链接 Animals and Puzzle 题意 给出一个1e3 * 1e3的01矩阵,给出t个询问,每个询问形如x1,y1,x2,y2 你需要回答在以$(x1, y1)$为左上角,$(x1, ...
- Codeforces Round #371 (Div. 1) D. Animals and Puzzle 二维倍增
D. Animals and Puzzle 题目连接: http://codeforces.com/contest/713/problem/D Description Owl Sonya gave a ...
- 【CodeForces】713 D. Animals and Puzzle 动态规划+二维ST表
[题目]D. Animals and Puzzle [题意]给定n*m的01矩阵,Q次询问某个子矩阵内的最大正方形全1子矩阵边长.n,m<=1000,Q<=10^6. [算法]动态规划DP ...
- Codeforces Round #371 (Div. 1) D - Animals and Puzzle 二维ST表 + 二分
D - Animals and Puzzle #include<bits/stdc++.h> #define LL long long #define fi first #define s ...
- Animals and Puzzle
Animals and Puzzle time limit per test 5 seconds memory limit per test 512 megabytes input standard ...
- codeforces 713D D. Animals and Puzzle 二分+二维rmq
题目链接 给一个01矩阵, 然后每个询问给出两个坐标(x1, y1), (x2, y2). 问你这个范围内的最大全1正方形的边长是多少. 我们dp算出以i, j为右下角的正方形边长最大值. 然后用二维 ...
- CodeForces 35D Animals
G - Animals Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit ...
- Codeforces 761E Dasha and Puzzle(构造)
题目链接 Dasha and Puzzle 对于无解的情况:若存在一个点入度大于4,那么直接判断无解. 从根结点出发(假设根结点的深度为0), 深度为0的节点到深度为1的节点的这些边长度为2^30, ...
- 『NYIST』第九届河南省ACM竞赛队伍选拔赛[正式赛二]--Codeforces -35D. Animals
D. Animals time limit per test 2 seconds memory limit per test 64 megabytes input input.txt output o ...
随机推荐
- 【转】java_web开发入门
转载地址:http://www.cnblogs.com/xiaoqv/archive/2011/12/10/2283348.html 一.Tomcat服务器常见启动问题:(1).Java_home环境 ...
- 开源数据库连接池proxool
可以根据自己的实际情况,选择不同的配置,可以选择properties.XML.Servlet等配置,官方网站上都有介绍. 1.下载proxool 地址:http://proxool.sourcef ...
- Android 读取Assets中资源
//读取文件 private static String getFromAssets(Context context, String fileName) { String result = " ...
- 20150812 Asp.net 父窗体获取子窗体的返回值,更新父窗体文本控件(应用)
1. 父窗体 **************************************** using System;using System.Collections;using System.C ...
- UVa 11624,两次BFS
题目链接:http://vjudge.net/contest/132239#problem/A 题目链接:https://uva.onlinejudge.org/external/116/11624. ...
- STM32/GD32上内存堆栈溢出探测研究
无数次遭受堆栈溢出折磨,随着系统变得复杂,故障点越来越难以查找!主要溢出情况如下:1,一般RAM最后两块空间是堆Heap和栈Stack,堆从下往上用,栈从上往下用,任意一个用完,都会进入对方的空间2, ...
- winform中利用反射实现泛型数据访问对象基类(2)
在1的基础上做了一点改进 参数化处理 看上去更简洁 无主键情况下 update 方法需要改进 insert delete没有问题 /// <summary> /// DAO基类 ...
- Failed to start component [StandardEngine[Catalina].StandardHost[localhost....
今天我用了近一天的时间研究一个错误,早上写代码是遇到一个 错误严重错误代码如下: 严重: ContainerBase.addChild: start: org.apache.catalina.Life ...
- C语言100个经典算法
POJ上做做ACM的题 语言的学习基础,100个经典的算法C语言的学习要从基础开始,这里是100个经典的算法-1C语言的学习要从基础开始,这里是100个经典的算法 题目:古典问题:有一对兔子,从出生后 ...
- Intent官方教程(1)简介和作用
Intents An Intent is a messaging object you can use to request an action from another app component. ...