博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
uva 1312 - Cricket Field
阅读量:4074 次
发布时间:2019-05-25

本文共 1228 字,大约阅读时间需要 4 分钟。

题目大意:

在w*h的坐标上给n个点, 然后求一个最大的矩形,使得这个矩形内(不包括边界)没有点,注意边界上是可以有点的。

首先要把这些坐标进行离散化,离散话时要注意一点,如果有两个点原来坐标不是相邻的,但是离散化以后却变成相邻了,这时候要在它们之间加上一个点。

预处理后,枚举矩形上下界,然后再用O(n)的复杂度找出左右边界。

代码:

#include
#include
#include
#include
#include
using namespace std;const int MAXN = 120;int n,w,h;int row, col;int d[MAXN];int arr[MAXN][2];int x[MAXN], y[MAXN];int idx[10010], idy[10010];int mat[MAXN][MAXN];inline void input(){ x[0] = y[0] = 0; row = col = 1; // 输入并离散化 for(int i=0; i
0){ tmp = mat[up][j]-mat[low][j] - (mat[up][j-1]-mat[low][j-1]); }else{ tmp = mat[up][j]-mat[low][j]; } if(tmp == 0){ d[j] = d[j-1] + 1; int low_x = max(low, 0); int low_y = max(j-d[j], 0); int up_x = min(row-1, up+1); int up_y = min(col-1, j+1); int hh = x[up_x] - x[low_x]; int ww = y[up_y] - y[low_y]; int ll = min(hh, ww); if(ll > maxLen){ maxLen = ll; max_x = low_x; max_y = low_y; xx = up_x; yy = up_y; } } } }} printf("%d %d %d\n", x[max_x], y[max_y], maxLen);}int main(){ int nCase; bool first=true; scanf("%d", &nCase); while(nCase--){ scanf("%d%d%d", &n, &w, &h); first ? first=false : putchar('\n'); if(n==0){ printf("%d %d %d\n",0,0,min(w,h)); continue; } input(); solve(); } return 0;}

转载地址:http://lszni.baihongyu.com/

你可能感兴趣的文章
net TCP/IP / TIME_WAIT / tcpip / iperf / cain
查看>>
webServer kzserver/1.0.0
查看>>
OS + Unix IBM Aix basic / topas / nmon / filemon / vmstat / iostat / sysstat/sar
查看>>
my ReadMap subway / metro / map / ditie / gaotie / traffic / jiaotong
查看>>
OS + Linux DNS Server Bind
查看>>
linux下安装django
查看>>
Android 解决TextView设置文本和富文本SpannableString自动换行留空白问题
查看>>
最完整的Java IO流学习总结
查看>>
Android开发中Button按钮绑定监听器的方式完全解析
查看>>
Android自定义View实现商品评价星星评分控件
查看>>
postgresql监控工具pgstatspack的安装及使用
查看>>
postgresql查看表的和索引的情况,判断是否膨胀
查看>>
postgresql中根据oid和filenode去找表的物理文件的位置
查看>>
postgresql减少wal日志生成量的方法
查看>>
swift中单例的创建及销毁
查看>>
获取App Store中App的ipa包
查看>>
iOS 关于pods-frameworks.sh:permission denied报错的解决
查看>>
设置RGBColor
查看>>
设置tabbaritem的title的颜色及按钮图片
查看>>
动态设置label的高度
查看>>