HDU 5301 Buildings
来源:互联网 发布:wow强者的旗帜 淘宝 编辑:程序博客网 时间:2024/06/05 23:42
分析
你当前的任务是要为将于HZXJHS建造的住宅楼做一份地面规划。所以你需要找到一个合理的方式划分地面以建造矩形的楼墙。每一面墙都应该和建筑物的边平行。
这块地皮可以视为一个长宽
另外,这些楼群必须完全覆盖这块地皮,除了一个预先规划的位于square
)。这些楼可以并拢,但不能和其他楼共占一块地面。
举一个栗子,当
除此之外,考虑采光每一栋楼都应预留开窗的位置。因此,每一栋楼为了避免其采光被另外的楼遮挡,都应有一面墙是直接面向这个地皮的外围,才能开窗。
你的老板XXY希望你能在这块地皮上尽可能规划建造较小占地面积的楼(为了采光你可能需要扩大占地面积),给出该方案中面积最大的楼的占地面积。
简要地读懂题意后,思考这个类似于拼积木
的问题。
首先是楼的大小,因为要求尽可能的占地小,所以其大小应该为
再而是考虑如何规划,先忽视广场这个影响因素。因为其楼这个矩形至少一边必须与地皮这个矩形的一边重合。不妨先在外围用
同理,
此时,引入广场这个影响因素,显然,我们只需要考虑这个广场到四条边的方向上的方块如何合并。自然我们会考虑取这四方向上最长的,即是我们要确定的
但是如果存在这样的情况,当
为了确保讨论不重复,现确定下面讨论的方向,不妨定
取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
Additionally, the apartments must completely cover the floor without one
For this example, this is a sample of
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
For each testcase, only four space-separated integers,
Output
For each testcase, print only one interger, representing the answer.
Sample Input
2 3 2 2
3 3 1 1
Sample Output
1
2
- HDU 5301 - Buildings(技巧)
- hdu 5301 Buildings
- HDU - 5301 Buildings
- hdu 5301 Buildings
- HDU 5301 Buildings
- HDU 5301Buildings
- HDU 5301 Buildings
- hdu 5301 Buildings
- hdu 5301 Buildings
- hdu 5301(枚举) Buildings
- HDU 5301 Buildings
- hdu 5301 Buildings
- HDU 5301 Buildings (乱搞)
- 4302: Hdu 5301 Buildings
- HDU 5301 Buildings(思维题)
- HDU 5301 Buildings(找规律)
- HDU 5301 Buildings(思维)
- HDU 5301 Buildings(机智)
- 学习笔记11:Scala中伴生类和伴生对象中Apply方法的应用
- hadoop1
- 利用tcpdump抓包工具监控TCP连接的三次握手和断开连接的四次挥手
- 如何用python实现剔除列表中相同的元素
- 黑马程序员——Java 多线程
- HDU 5301 Buildings
- Core Animation编程指南
- CentOS服务器初始化设置---安全设置
- Git 版本控制使用
- 咏蚁
- Java Fibonacci数列
- 有序表操作
- uva 297 dfs
- 初步学习MVC的白痴问题的解决记录(一)