当前位置: 首页 > news >正文

P2216 [HAOI2007] 理想的正方形

P2216 [HAOI2007] 理想的正方形

 

#include <bits/stdc++.h>
using namespace std;const int maxn = 1e3 + 10;
int a,b,n;
int c[maxn][maxn];
deque <int> dq1,dq2;
int max1[maxn][maxn],min1[maxn][maxn];
int max2[maxn][maxn],min2[maxn][maxn];int ans = 2e9;int main(){ios::sync_with_stdio(0);cin.tie(0);cin >> a >> b >> n; for(int i = 1; i <= a; i++){for(int j = 1; j <= b; j++){cin >> c[i][j];} }for(int i = 1; i <= a; i++){dq1.clear();dq2.clear();for(int j = 1; j <= b; j++){while(!dq1.empty() && j - dq1.front() + 1 > n) dq1.pop_front();while(!dq1.empty() &&c[i][dq1.back()] <= c[i][j]) dq1.pop_back();dq1.push_back(j);if(j >= n) max1[i][j - n + 1] = c[i][dq1.front()];while(!dq2.empty() && j - dq2.front() + 1 > n) dq2.pop_front();while(!dq2.empty() &&c[i][dq2.back()] >= c[i][j]) dq2.pop_back();dq2.push_back(j);if(j >= n) min1[i][j - n + 1] = c[i][dq2.front()];} }for(int j = 1; j <= b - n + 1; j++){dq1.clear();dq2.clear();for(int i = 1; i <= a; i++){while(!dq1.empty() && i - dq1.front() + 1 > n) dq1.pop_front();while(!dq1.empty() && max1[i][j] >= max1[dq1.back()][j]) dq1.pop_back();dq1.push_back(i);if(i >= n) max2[i - n + 1][j] = max1[dq1.front()][j];while(!dq2.empty() && i - dq2.front() + 1 > n) dq2.pop_front();while(!dq2.empty() && min1[i][j] <= min1[dq2.back()][j]) dq2.pop_back();dq2.push_back(i);if(i >= n) min2[i - n +1][j] = min1[dq2.front()][j];}}for(int i = 1; i <= a - n +1; i++){for(int j = 1; j <= b - n +1; j++){ans = min(ans,max2[i][j] - min2[i][j]);}}cout << ans;return 0;
}

  

http://www.gsyq.cn/news/7433.html

相关文章:

  • 2-sat板子
  • Node.js 中使用 .env 文件管理环境变量
  • pythonjs逆向 破解滑动验证码 - hello-*
  • Bun:不仅是新的JavaScript运行时,并且重塑了JavaScript工具链
  • AI Agent 与 MCP 核心解析与企业级应用指南
  • P3934 [Ynoi Easy Round 2016] 炸脖龙 I 做题记录
  • 正确输入连字号、连接号、破折号和负号
  • python基础-元组
  • python基础篇-list(列表)
  • vscode使用powershell中文乱码
  • Untitled
  • 完整教程:论园区电气安全管理系统的重要性
  • 没搞懂的package.json
  • 你应该考虑放弃 react-router 的数据路由模式,改而使用更加适合国内版本的封装版本(包含完整可 CV 的模版)
  • 基于CSU8RP1186芯片的握力器解决方案
  • 深入解析:C++ 内存管理:从底层原理到实战应用
  • sass踩坑:@import导致前端项目打包体积膨胀
  • 深入解析:Java 设计模式之桥接模式(Bridge Pattern)
  • 【AP出版】第四届数理统计与经济分析国际学术会议 (MSEA 2025)
  • 数据结构 Trick 之:区间子区间计数
  • mapstruct.Mapper|Mapping详解
  • XXL-JOB(3)
  • web17(备份的sql文件泄露)
  • web11(通过Dns检查查询Flag)
  • 立创商城
  • ctfshow web 10
  • KEITHLEY 数字万用表
  • 大数据毕业设计选题推荐-基于大数据的慢性肾病数据可视化分析系统-Spark-Hadoop-Bigdata - 详解
  • get请求图片文件转为base64编码
  • BMS与威纶通人机界面通信问题