Codeforces713D. Animals and Puzzle
$n<=1000,m<=1000$,$n*m$的01矩阵,给$t<=1000000$个询问,每次问一个矩形中最大的1正方形的边长。
先想想不考虑“一个矩形中”的限制,那记$f(i,j)$--以$(i,j)$为右下角的最大的正方形,那
很好,那现在加入一个边界限制,由于边长r的正方形同时也是边长r-1,r-2……的,那来二分答案吧,现在对二分的答案$x$就检查一个区域里的$f$数组中最大的那一个是否大于等于$x$。查静态区间最大,用ST表啦!拓展到二维情况即可。
![](/assets/blank.gif)
![](/assets/blank.gif)
1 #include<string.h> 2 #include<stdlib.h> 3 #include<stdio.h> 4 //#include<math.h> 5 //#include<assert.h> 6 #include<algorithm> 7 //#include<iostream> 8 //#include<bitset> 9 using namespace std; 10 11 int n,m,t; 12 #define maxn 1011 13 int a[maxn][maxn],Log[maxn];short rmq[maxn][maxn][12][12]; 14 15 int x1,x2,y1,y2; 16 int rmqquery(int x1,int y1,int x2,int y2) 17 { 18 int p=Log[x2-x1+1],q=Log[y2-y1+1]; 19 return max(max(rmq[x1][y1][p][q],rmq[x2-(1<<p)+1][y1][p][q]) 20 ,max(rmq[x1][y2-(1<<q)+1][p][q],rmq[x2-(1<<p)+1][y2-(1<<q)+1][p][q])); 21 } 22 bool check(int len) {return rmqquery(x1+len-1,y1+len-1,x2,y2)>=len;} 23 int main() 24 { 25 scanf("%d%d",&n,&m); 26 for (int i=1;i<=n;i++) 27 for (int j=1;j<=m;j++) 28 scanf("%d",&a[i][j]); 29 for (int i=1;i<=n;i++) 30 for (int j=1;j<=m;j++) 31 if (a[i][j]==0) rmq[i][j][0][0]=0; 32 else rmq[i][j][0][0]=min(rmq[i][j-1][0][0],min(rmq[i-1][j][0][0],rmq[i-1][j-1][0][0]))+1; 33 Log[0]=-1; for (int i=1,to=max(n,m);i<=to;i++) Log[i]=Log[i>>1]+1; 34 for (int q=1;(1<<q)<=m;q++) 35 for (int i=1;i<=n;i++) 36 for (int j=1,to=m-(1<<q)+1;j<=to;j++) 37 rmq[i][j][0][q]=max(rmq[i][j][0][q-1],rmq[i][j+(1<<(q-1))][0][q-1]); 38 for (int p=1;(1<<p)<=n;p++) 39 { 40 for (int i=1,to=n-(1<<p)+1;i<=to;i++) 41 for (int j=1;j<=m;j++) 42 rmq[i][j][p][0]=max(rmq[i][j][p-1][0],rmq[i+(1<<(p-1))][j][p-1][0]); 43 for (int q=1;(1<<q)<=m;q++) 44 for (int i=1,to=n-(1<<p)+1;i<=to;i++) 45 for (int j=1,to=m-(1<<q)+1;j<=to;j++) 46 rmq[i][j][p][q]=max(rmq[i][j][p][q-1],rmq[i][j+(1<<(q-1))][p][q-1]); 47 } 48 scanf("%d",&t); 49 while (t--) 50 { 51 scanf("%d%d%d%d",&x1,&y1,&x2,&y2); 52 int L=0,R=min(x2-x1+1,y2-y1+1); 53 while (L<R) 54 { 55 const int mid=(L+R+1)>>1; 56 if (check(mid)) L=mid; 57 else R=mid-1; 58 } 59 printf("%d\n",L); 60 } 61 return 0; 62 }
View Code
转载于:https://www.cnblogs.com/Blue233333/p/8308328.html
Codeforces713D. Animals and Puzzle相关推荐
- 2016区域赛前冲刺训练
UPD 2016.10.23 shift-and (2题) Codeforces 训练 现在已经完成了: 191 [Codeforces Round #377] (6/6) Div 2 A Buy a ...
- 二十一世纪大学英语读写教程(第三册)学习笔记(原文)——2 - The Titanic Puzzle(泰坦尼克难题——女权主义者应该接受优先坐上救生艇吗)
Unit 2 - The Titanic Puzzle - Should a good feminist accept priority seating on a lifeboat?(泰坦尼克难题-- ...
- 学会在Unity中创建一个Match-3益智游戏 Learn To Create a Match-3 Puzzle Game in Unity
MP4 |视频:h264,1280×720 |音频:AAC,44.1 KHz,2 Ch 语言:英语+中英文字幕(根据原英文字幕机译更准确) |时长:48场讲座(6h 38m) |大小解压后:2.8 G ...
- 【杭电ACM】1097 A hard puzzle
[杭电ACM]1097 A hard puzzle http://acm.hdu.edu.cn/showproblem.php?pid=1097 先用int手写了算法结果竟然wrong answer ...
- Eight puzzle --HOJ 11918
1.题目类型:模拟.哈希表.BFS. 2.解题思路:(1)模拟Eigh Puzzle的变换方式,并记录在数组中 :(2)由于变换的最终结果相同,所以采用反向的BFS遍历所有情况,并记录所有情况:(3) ...
- 补第四周作业总结——8 puzzle
8 puzzle已经提供了解决思路,早期的人工智能算法A.我只能感觉它的神奇,但是没法创造性地使用它.只能按部就班地完成这周的作业. 难点在于对过程的不理解.这个33的格子搜索算法没有尽头,随着步数的 ...
- UVA227 Puzzle
问题链接:UVA227 Puzzle.基础训练级的问题,用C语言编写程序. 问题简述:一个5×5的网格,一个格子是空的,其他格子各有一个字母,一共有四种指令:A,B,L,R,分别表示把空格上.下.左. ...
- UVa10639 Square Puzzle(WA)
例子通过了,并且udebug上的例子也通过了,但是提交还是错误. 针对特殊情况: 3 4 7 0 2 1 2 2 3 3 2 4 2 4 4 0 4 7 0 0 4 0 4 2 3 2 2 1 1 2 ...
- 【37.50%】【codeforces 745B】Hongcow Solves A Puzzle
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
最新文章
- Document对象内容集合
- JAVA多线程--Thinking in java
- Android的Application的生命周期方法
- 蚂蚁金服面试经历!临场发挥!
- 动态规划--Leetcode63.不同路径二
- 利用锁分析器进行线程竞争检测
- 跟bWAPP学WEB安全(PHP代码)--SSL(Server-Side-Include)漏洞
- 4.2 tensorflow2实现多总体位置参数趋势性检验——python实战
- 关关采集V3.5高级版杰奇全版本通用编码版
- matlab二重定积分_MATLAB计算二重数值积分(dblquad)
- Python openpyxl 删除excel有删除线的文字
- vue3中的Suspense
- Boot(重点SCSS☆☆☆☆☆)(day03)
- 市场调研报告-全球与中国燃油泄漏检测设备市场现状及未来发展趋势
- 在.NET中实现彩色光标/动画光标和自定义光标[转]
- 金仓数据库 KingbaseES 与 Oracle 的兼容性说明(4. SQL)
- 软件测试知识点(持续更新)
- 条码打印机.双面胶.樱花红
- C语言程序设计谭浩强第五版复习梳理2
- 本草纲目pdf彩图版下载_本草纲目下载|本草纲目彩色图集精编珍藏版下载pdf高清版下载_最火手机站...
热门文章
- git介绍,安装(手把手),命令与使用(包含IDEA操作,github,gitee的万字图文详述)
- 安装MySQL 5.6.13.1出现 Urhandled exception has occurred in your application. If you click Continue....
- android学习日记01--综述
- 计算机设备自动关机,电脑如何设置自动关机
- 个人Internet网站创建过程详解
- react-native 中的元素(zIndex,elevation)层级关系
- 微服务架构下的分布式数据存储-技术之家
- linux网络编程中listen函数 backlog的含义
- 少儿编程 实操题搭建搅拌器 电子学会机器人等级考试一级真题解析2018-12
- 计算机网络读后感500字,骆驼祥子读后感500字