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. 数据库_11_1~10总结回顾+奇怪的NULL

    校对集问题: 比较规则:_bin,_cs,_ci利用排序(order by) 另外两种登录方式: 奇怪的NULL: NULL的特殊性:

  2. 【转】关于编写WPF UserControl时提示The name 'InitializeComponent' does not exist in the current contextr的解决!

    1.打开.csproj(工程)文件. 2.找到<Import Project="$(MSBuildBinPath)/Microsoft.CSharp.targets" /&g ...

  3. zeromq编译与应用

    libzmq是c++语言开发的,正式版本在这里: https://github.com/zeromq/libzmq/releases 到这篇文件发布为止,正式稳定版是4.2.2 1,按照给出的链接下载 ...

  4. 单片微机原理P1:80C51指令系统和编程方法

    0. 寻址方式 寻址方式在汇编中是很重要的,汇编所有的操作都是和和内存或者寄存器打交道的,在80C51里面一共7种寻址方式.   1. 立即寻址: 这个没什么好说的,就是往寄存器或者内存里面写立即数, ...

  5. 出现了错误。详细消息: 3 uncommitted changes would be overwritten by merge

    merge manual中有一条警告: 出现了错误.详细消息: 3 uncommitted changes would be overwritten by merge 有未提交修改情况下,不要执行me ...

  6. 在single模式修改密码

    当前是在CentOS 6.5 的命令行模式下 开机后在这个界面按随意键 接着来到新界面中,在当前选项中按下e键: 接着来到新界面,选择第二个,按下e键: 在这里我们输入single接着回车: 接着回到 ...

  7. ps指令详解

    ps aux #显示出系统上的全部进程ps -ef #显示出系统上的全部进程,且显示出PPID一栏ps -ljF #仅显示与本终端上开启的进程 选项:-t 终端名称1 终端名称2 #指定关联的多个终端 ...

  8. python:零散记录

    1.rstrip()删除末尾指定字符串 例如:A = '1,2,3,4,5,' B = A.rstrip(',') B = '1,2,3,4,5' 2.isdigit()方法 Python isdig ...

  9. transformer模型解读

    最近在关注谷歌发布关于BERT模型,它是以Transformer的双向编码器表示.顺便回顾了<Attention is all you need>这篇文章主要讲解Transformer编码 ...

  10. terminology(术语)

    1.declaration:告诉编译器某个标识符的name和type,同时略去具体细节. extern int x;     //对象(object)声明式 std::size_t  numDigit ...