题意:一个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的更多相关文章

  1. Codeforces 713D Animals and Puzzle(二维ST表+二分答案)

    题目链接 Animals and Puzzle 题意  给出一个1e3 * 1e3的01矩阵,给出t个询问,每个询问形如x1,y1,x2,y2 你需要回答在以$(x1, y1)$为左上角,$(x1, ...

  2. 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 ...

  3. 【CodeForces】713 D. Animals and Puzzle 动态规划+二维ST表

    [题目]D. Animals and Puzzle [题意]给定n*m的01矩阵,Q次询问某个子矩阵内的最大正方形全1子矩阵边长.n,m<=1000,Q<=10^6. [算法]动态规划DP ...

  4. 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 ...

  5. Animals and Puzzle

    Animals and Puzzle time limit per test 5 seconds memory limit per test 512 megabytes input standard ...

  6. codeforces 713D D. Animals and Puzzle 二分+二维rmq

    题目链接 给一个01矩阵, 然后每个询问给出两个坐标(x1, y1), (x2, y2). 问你这个范围内的最大全1正方形的边长是多少. 我们dp算出以i, j为右下角的正方形边长最大值. 然后用二维 ...

  7. CodeForces 35D Animals

    G - Animals Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit  ...

  8. Codeforces 761E Dasha and Puzzle(构造)

    题目链接 Dasha and Puzzle 对于无解的情况:若存在一个点入度大于4,那么直接判断无解. 从根结点出发(假设根结点的深度为0), 深度为0的节点到深度为1的节点的这些边长度为2^30, ...

  9. 『NYIST』第九届河南省ACM竞赛队伍选拔赛[正式赛二]--Codeforces -35D. Animals

    D. Animals time limit per test 2 seconds memory limit per test 64 megabytes input input.txt output o ...

随机推荐

  1. 线程属性pthread_attr_t

    转:http://blog.sina.com.cn/s/blog_6dc9e4cf0100xcvk.html1.    线程属性:             使用pthread_attr_t类型表示,我 ...

  2. SQL数据类型大全 《转自网络》

    数据类型是数据的一种属性,表示数据所表示信息的类型.任何一种计算机语言都定义了自己的数据类型.当然,不同的程序语言都具有不同的特点,所定义的数据类型的种类和名称都或多或少有些不同.SQLServer ...

  3. 关闭用miniUI打开的窗口

    miniUI打开的窗口用window.close关闭无效, 应该用window.CloseOwnerWindow();

  4. SlickGrid example 5:带子项的展开收缩

    带子项的展开收缩.   代码: <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Ty ...

  5. Check the difficulty of problems

    Check the difficulty of problems Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 5830 Acc ...

  6. jquery闭包的使用

    <div id="divTest"> Test </div> <br /> <hr /> <div id="divT ...

  7. ThreadLocal深入理解二

    转载:http://doc00.com/doc/101101jf6 今天在看之前转载的博客:ThreadLocal的内部实现原理.突然有个疑问, 按照threadLocal的原理, 当把一个对象存入到 ...

  8. 为测试框架model类自动生成xml结果集

    问题:有大量类似于theProductId这样名字的字符串需要转换成the_product_id这种数据库column名的形式. 思路:见到(见)大写字母(缝)就插入(插)一个“_”字符(针)进去,最 ...

  9. WebForm在JS中从Dropdownlist添加数据,在C#段读取

    (1)页面设置和JS代码 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Def ...

  10. JAVA中线程池启动定时任务

    /** * 用线程池启动定时器 * @param args */ public static void main(String[] args) { //10秒启动 Executors.newSched ...