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 ...
随机推荐
- C#:实现接口中定义的事件
public delegate void TestDelegate(); // delegate declaration public interface ITestInterface { event ...
- php header()函数设置页面Cache缓存
header()函数在php的使用很大,下面我来介绍利用它实现页面缓存的一些方法,但使用header前必须注意,在它之前不能任何输出,包括空格. 手册上,我们对于cache都是写着如何设置,以便让代码 ...
- css常用命名规则
(一)常用的CSS命名规则 头:header 内容:content/container 尾:footer 导航:nav 侧栏:sidebar 栏目:column 页面外围控制整体布局宽度:wrappe ...
- [团队项目]SCRUM项目6.0 7.0 (新)
6.0----------------------------------------------------- sprint演示 1.坚持所有的sprint都结束于演示. 团队的成果得到认可,会感觉 ...
- hdu1024 Max Sum Plus Plus
动态规划,给定长度为n(≤1e6)的整数数组和整数m,选取m个连续且两两无交集的子区间,求所有方案中使得区间和最大的最大值. dp[i][j]表示结束位置(最后一个区间最后一个元素的位置)为i且选取区 ...
- CyclicBarrier原理
转载:http://www.cnblogs.com/skywang12345/p/3533995.html CyclicBarrier是一个同步辅助类,允许一组线程互相等待,直到到达某个公共屏障点 ( ...
- 简单的ajax封装
// ajax发送post请求返回 json 数据function requestJSON(params) { params.dataType = 'json'; sendPost(par ...
- centos6.5用户管理
一.centOS6.5用户管理命令 useradd 新增用户 userdel 删除用户 passwd 修改用户密码 二.命令的使用 useradd useradd admin userdel us ...
- __NSCFConstantString
-[__NSCFConstantString size]: unrecognized selector sent to instance 0x53ea70 该错误是在我将NSString类型的参数赋值 ...
- 在centos6.3用yum安装redis
一.centos默认的安装源在官方centos.org上,而redis在第三方的yum源里,所以无法安装,非官方的yum推荐用fedora的epel仓库.当然也可通过配置 /etc/yum.repos ...