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 ...
随机推荐
- Hadoop集群管理之配置文件
一.配置文件列表如下: [hadoop@node1 conf]$ pwd /app/hadoop/conf [hadoop@node1 conf]$ echo $HADOOP_HOME /app/ha ...
- Android如何区分app原生和webview实现
在开发Android app时,特别是强内容展现型的功能,会想在原生native实现和web实现中做选择,做这种选择的时候,难免想看看竞品或其它app类似功能是用哪种方式实现的.但是如何判断其它app ...
- Unix/Linux编程实践教程(一:进程、管道)
execvp在程序中启动新程序: 用fork创建新进程: forkdemo2代码: 测试fork的时候参考<Linux权威指南>阅读笔记(3) 使用了patch: [root@local ...
- 不定参数的传递VA_LIST的用法
VA_LIST的用法:(1)首先在函数里定义一具VA_LIST型的变量,这个变量是指向参数的指针: (2)然后用VA_START宏初始化变量刚定义的VA_LIST变量,使其指向第一个可 变参数的地址: ...
- bianwu 哈希表输出到 excel
一.输出到excel 函数: protected void InputFileTheme(object[] Header,object [] DataFileds,string sql,string ...
- [ios][opengles]opengles纹理贴图
参考:http://www.cnblogs.com/andyque/archive/2011/09/02/2155061.html
- easyrtc-server在ubuntu14.04上的安装方法
easyrtc 官网 http://easyrtc.com/ 1.安装nodejs,安装npm (不知道如何安装请google一下) 2. 查看运行easyrtc 所需要的js 包,在easyrtc ...
- 20150612_Andriod contextual action mode 菜单
参考地址:http://www.xuebuyuan.com/1114028.html http://www.cnblogs.com/mengdd/p/3564782.html ...
- Jnotify文件监控的用法以及Jar文件导入的方法
简介Jnotiy, 支持动态监控(支持级联监控)文件夹和文件的jar包.在linux中,调用linux底层的jnotify服务.在windows中,需要添加附件的dll文件. 因为通用的Maven仓库 ...
- MyBatis 3与spring整合之使用SqlSession
SqlSessionTemplate是MyBatis-Spring的核心.这个类负责管理MyBatis的SqlSession.调用MyBatis的SQL方法. SqlSessionTemplate是线 ...