Buildings

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)

Total Submission(s): 759    Accepted Submission(s): 210

Problem 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 

rev=2.4-beta-2" alt="" style="">,
where each apartment is a smaller rectangle with dimensions 

rev=2.4-beta-2" alt="" style="">

rev=2.4-beta-2" alt="" style="">

rev=2.4-beta-2" alt="" style=""> located
inside. For each apartment, its dimensions can be different from each other. The number 

rev=2.4-beta-2" alt="" style=""> and 

rev=2.4-beta-2" alt="" style=""> must
be integers.



Additionally, the apartments must completely cover the floor without one 

rev=2.4-beta-2" alt="" style="">

rev=2.4-beta-2" alt="" style=""> square
located on 

rev=2.4-beta-2" alt="" style="">.
The apartments must not intersect, but they can touch.



For this example, this is a sample of 

rev=2.4-beta-2" alt="" style="">

rev=2.4-beta-2" alt="" style="">

rev=2.4-beta-2" alt="" style="">

rev=2.4-beta-2" alt="" style="">

rev=2.4-beta-2" alt="" style="">.






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 

rev=2.4-beta-2" alt="" style="">

rev=2.4-beta-2" alt="" style=""> testcases.

For each testcase, only four space-separated integers, 

rev=2.4-beta-2" alt="" style="">

rev=2.4-beta-2" alt="" style="">

rev=2.4-beta-2" alt="" style="">

rev=2.4-beta-2" alt="" style="">

rev=2.4-beta-2" alt="" style="">

rev=2.4-beta-2" alt="" style="">

rev=2.4-beta-2" alt="" style="">

rev=2.4-beta-2" alt="" style="">

rev=2.4-beta-2" alt="" style="">

rev=2.4-beta-2" alt="" style="">

rev=2.4-beta-2" alt="" style="">

rev=2.4-beta-2" alt="" style="">.

 
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
Hint
Case 1 :

You can split the floor into five apartments. The answer is 1. Case 2:

You can split the floor into three rev=2.4-beta-2" alt="" style=""> apartments and two rev=2.4-beta-2" alt="" style=""> apartments. The answer is 2.
If you want to split the floor into eight apartments, it will be unacceptable because the apartment located on (2,2) can't have windows.
 
Source

解题思路:

假设没有不合法的块,那结果就是长和宽中最小值的一半,而,不合法的块所影响的仅仅有它周围的四块,计算出这四块距离四个边的距离的最小值,就是加入上不合法块之后该块所须要的最长距离。

须要注意特判一中情况。即不合法块在正中间的时候,并不造成影响。

#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
using namespace std;
int n, m, x, y;
int main()
{
while(scanf("%d%d%d%d", &n, &m, &x, &y)!=EOF)
{
if(n == m && (n % 2 == 1 && m % 2 == 1) && (x == y && x == (n+1)/2))
{
cout << (n -1) / 2 << endl;
continue;
}
int Min = min(n, m); int ans;
if(Min & 1) ans = (Min + 1) / 2;
else ans = Min / 2;
int res = -10;
int xx = x - 1, yy = y;
if(xx >= 1 && yy >= 1) res = max(res, min(xx-1,min(yy-1,m-yy)));
xx = x, yy = y-1;
if(xx >= 1 && yy >= 1) res = max(res, min(min(xx-1,n-xx),yy-1));
xx = x + 1, yy = y;
if(xx <=n && yy >= 1) res = max(res, min(n-xx,min(yy-1,m-yy)));
xx = x, yy = y+1;
if(xx >= 1 && yy <= m) res = max(res, min(min(xx-1,n-xx),m-yy));
res += 1;
ans = max(ans, res);
printf("%d\n", ans);
}
return 0;
}

 

HDU 5301 Buildings(2015多校第二场)的更多相关文章

  1. hdu 5301 Buildings (2015多校第二场第2题) 简单模拟

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5301 题意:给你一个n*m的矩形,可以分成n*m个1*1的小矩形,再给你一个坐标(x,y),表示黑格子 ...

  2. hdu 5308 (2015多校第二场第9题)脑洞模拟题,无语

    题目链接:http://acm.hdu.edu.cn/listproblem.php?vol=44 题意:给你n个n,如果能在n-1次运算之后(加减乘除)结果为24的输出n-1次运算的过程,如果不能输 ...

  3. 2015多校联合训练赛hdu 5301 Buildings 2015 Multi-University Training Contest 2 简单题

    Buildings Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Tota ...

  4. hdu 5305 Friends(2015多校第二场第6题)记忆化搜索

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5305 题意:给你n个人,m条关系,关系可以是online也可以是offline,让你求在保证所有人on ...

  5. HDU 5308 I Wanna Become A 24-Point Master(2015多校第二场)

    I Wanna Become A 24-Point Master Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 ...

  6. HDU 5303 Delicious Apples (2015多校第二场 贪心 + 枚举)

    Delicious Apples Time Limit: 5000/3000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Other ...

  7. HDU 5289 Assignment(2015 多校第一场二分 + RMQ)

    Assignment Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total ...

  8. 【HDU 5305】Friends 多校第二场(双向DFS)

    依据题意的话最多32条边,直接暴力的话 2 ^ 32肯定超时了.我们能够分两次搜索时间复杂度降低为 2 * 2  ^ 16 唯一须要注意的就是对眼下状态的哈希处理. 我採用的是 十进制表示法 跑的还是 ...

  9. hdu 6053: TrickGCD (2017 多校第二场 1009) 【莫比乌斯 容斥原理】

    题目链接 定义f[n]表示n是最大公约数情况下的计数,F[n]为n是公约数情况下的计数 (可以和 http://www.cnblogs.com/Just--Do--It/p/7197788.html  ...

随机推荐

  1. QT_3

    1.QT中命名的规范和常用的快捷键 1.1 命名规范: 类名:首字母大写    多个单词时单词与单词之间首 字母大写 函数名:变量名称   首字母小写    多个单词时,单词和单词之间首字母大写 1. ...

  2. LeetCode(87) Gray Code

    题目 The gray code is a binary numeral system where two successive values differ in only one bit. Give ...

  3. POJ 3522 Slim Span (Kruskal枚举最小边)

    题意: 求出最小生成树中最大边与最小边差距的最小值. 分析: 排序,枚举最小边, 用最小边构造最小生成树, 没法构造了就退出 #include <stdio.h> #include < ...

  4. [MVC]View

    /Views/_ViewStart.cshtml 文件会在其他视图文档被加载之前被载入,代码如下: @{ Layout = "~/Views/Shared/_Layout.cshtml&qu ...

  5. Android开发——流量统计

    1. 获取应用UID 在设备的proc目录下我们可以看到一些比较熟悉的目录/文件,比如data,system,cpuinfo(获取CPU信息)等,其中uid_stat的各个以应用Uid命名的目录下,便 ...

  6. jmeter-如何进行参数化-循环读取参数

    在进行测试的时候,测试数据是一项重要的准备工作,每次迭代的数据当不一样的时候,需要进行参数化,从参数化的文件中来读取测试数据. 本经验主要介绍的是用Csv Data配置元件来进行参数化. 方法/步骤 ...

  7. XV6调度

    调度 任何操作系统都可能碰到进程数多于处理器数的情况,这样就需要考虑如何分享处理器资源.理想的做法是让分享机制对进程透明.通常我们对进程造成一个自己独占处理器的假象,然后让操作系统的多路复用机制(mu ...

  8. Bone Collector II(01背包kth)

    The title of this problem is familiar,isn't it?yeah,if you had took part in the "Rookie Cup&quo ...

  9. Triangular Pastures (二维01背包)

    描述Like everyone, cows enjoy variety. Their current fancy is new shapes for pastures. The old rectang ...

  10. Codeforces Round #377 (Div. 2)部分题解A+B+C!

    A. Buy a Shovel 题意是很好懂的,一件商品单价为k,但他身上只有10块的若干和一张r块的:求最少买几件使得不需要找零.只需枚举数量判断总价最后一位是否为0或r即可. #include&l ...