HDU 5301 Buildings
2015-08-04 21:52
316 查看
分析
你当前的任务是要为将于HZXJHS建造的住宅楼做一份地面规划。所以你需要找到一个合理的方式划分地面以建造矩形的楼墙。每一面墙都应该和建筑物的边平行。这块地皮可以视为一个长宽n×mn \times m的矩形,在这块地皮上规划一每栋占地占地a×ba\times b的楼群。对于每一栋楼,其占地面积可以与其他楼不同。但其长宽abab都应是正整数。
另外,这些楼群必须完全覆盖这块地皮,除了一个预先规划的位于(x,y)(x,y)的占地1×11 \times1的广场(
square)。这些楼可以并拢,但不能和其他楼共占一块地面。
举一个栗子,当n=2,m=3,x=2,y=2n=2,m=3,x=2,y=2时,如下图所示。
除此之外,考虑采光每一栋楼都应预留开窗的位置。因此,每一栋楼为了避免其采光被另外的楼遮挡,都应有一面墙是直接面向这个地皮的外围,才能开窗。
你的老板XXY希望你能在这块地皮上尽可能规划建造较小占地面积的楼(为了采光你可能需要扩大占地面积),给出该方案中面积最大的楼的占地面积。
简要地读懂题意后,思考这个类似于
拼积木的问题。
首先是楼的大小,因为要求尽可能的占地小,所以其大小应该为1×b1\times b。例如2×22\times 2可以建造两栋1×21\times 2。
再而是考虑如何规划,先忽视广场这个影响因素。因为其楼这个矩形至少一边必须与地皮这个矩形的一边重合。不妨先在外围用1×11\times1,比如n=2,m=3n=2,m=3时,恰好铺满。再比如n=3,m=3n=3,m=3时,这时发现,(2,2)(2,2)这一块地方是没有办法采光的(暂不考虑广场),那么应该将其与其他楼合并,用1×21\times2的。
同理,n=4,m=4n=4,m=4时,有四块需要和其他楼合并。这是可以发现,找哪一个楼和中间楼合并才是需要解决的问题。只要有一个能合并,那么旁边与之平行的矩形均可以铺过。
此时,引入广场这个影响因素,显然,我们只需要考虑这个广场到四条边的方向上的方块如何合并。自然我们会考虑取这四方向上最长的,即是我们要确定的bb。
但是如果存在这样的情况,当n=5,m=6,x=4,y=5n=5,m=6,x=4,y=5时,最长的是4,但是4并不是正确答案,因为第4格可以由x方向的楼合并,此时其长度也仅为3。于是,有了这样一个大致思路。
为了确保讨论不重复,现确定下面讨论的方向,不妨定mm为长,nn为宽。
取y方向(与长平行)的两个长度的最小值p; 再取x方向(与宽平行)的两个长度的最大值q; 比较p+1和q的大小(即检查y方向是否能合并x方向的最后一个,以缩减一长度)得到最小的b值r。 但是如果r的长度超过了该矩形的一半显然是不合理的,可以由对称的思想对分这个地皮也能得解,比较r和地皮该方向的边长的一半得到解。
但是,这样的思路依然存在问题,如果这个矩形是正方形且广场建在中央呢?因为上述的讨论的最大值是边长的一半,但是这里如果是在中央,那么将小于边长的一半,所以还需要一个特判。
思路
因为解法中存在较多取大取小的方法,这里定义了宏,来实现取大取小,但不建议这么做,好像也只是代码长度短一些。代码
#include <cstdio> #define MAX(a, b) (a)>(b)?(a):(b) #define MIN(a, b) (a)<(b)?(a):(b) int n, m, x, y; int solve() { if (n > m) { int t = n; n = m; m = t; t = x; x = y; y = t; } if (n == m && x == y && n == (x<<1)-1) return (x-1); return MAX(MIN(MIN(y, m-y+1), MAX(x-1, n-x)), (n+1)>>1); } int main() { while (~scanf("%d%d%d%d", &n, &m, &x, &y)) printf("%d\n", solve()); return 0; }
题目
Description
Your current task is to make a ground plan for a residential building located in HZXJHS. So you must determine a way to split the floor building with walls to make apartments in the shape of a rectangle. Each built wall must be paralled to the building’s sides.The floor is represented in the ground plan as a large rectangle with dimensions n×mn \times m, where each apartment is a smaller rectangle with dimensions a×ba\times b located inside. For each apartment, its dimensions can be different from each other. The number aa and bb must be integers.
Additionally, the apartments must completely cover the floor without one 1×11 \times 1 square located on (x,y)(x,y). The apartments must not intersect, but they can touch.
For this example, this is a sample of n=2,m=3,x=2,y=2n=2,m=3,x=2,y=2.
To prevent darkness indoors, the apartments must have windows. Therefore, each apartment must share its at least one side with the edge of the rectangle representing the floor so it is possible to place a window.
Your boss XXY wants to minimize the maximum areas of all apartments, now it’s your turn to tell him the answer.
Input
There are at most 1000010000 testcases.For each testcase, only four space-separated integers, n,m,x,y(1≤n,m≤108,n×m>1,1≤x≤n,1≤y≤m)n,m,x,y(1\leq n,m \leq 10^8,n\times m > 1, 1\leq x \leq n, 1 \leq y \leq m).
Output
For each testcase, print only one interger, representing the answer.Sample Input
2 3 2 23 3 1 1
Sample Output
12
相关文章推荐
- DPDK 的 uio 以及 PMD 机制的实现
- minicom question
- 记录一下iOS的几个UIView的方法
- UI 03 自定义的Label-TextField视图 --- LTView
- iOS开发——UI进阶篇(十五)Quartz2D介绍
- UISwitch设置代理人 帮助实现变换背景颜色
- ios学习(UITabBarController)
- poj 2299 Ultra-QuickSort (树状数组+离散化)
- HD1047 Integer Inquiry 【大数问题】
- iOS UI04_Target-Action
- BIM建筑信息模型(Building Information Modeling)
- UI 03 UIViewController (视图控制器)的7个方法与视图的跳转
- Disque: antirez开发的开源分布式内存作业队列
- UI Overview
- 27.UIStepper和UISlider
- 通过UIView来模拟 实现 Button的点击效果
- ios使用storyboard中的segue从后往前进行传值
- 搜索 - hdu5288 OO’s Sequence
- JSP中页面跳转response.sendRedirect()和request.getRequestDispatcher()的区别
- 手势识别器(UIImageView)