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. django 127.0.0.1 将您重定向的次数过多

    "GET /?next=/%3Fnext%3D/%253Fnext%253D/ HTTP/1.1" 302 0 solution reference from django.con ...

  2. day13 函数模块之序列化 random 模块 os模块 sys模块 hashlib模块 collections模块

    json import json dic = {'k1':'v1','k2':'v2','k3':'v3'} str_dic = json.dumps(dic) #序列化:将一个字典转换成一个字符串 ...

  3. http请求响应格式

    当浏览器向Web服务器发出请求时,它向服务器传递了一个数据块,也就是请求信息,HTTP请求信息由3部分组成:l   请求方法URI协议/版本l   请求头(Request Header)l   请求正 ...

  4. List<T>排序

    List<Student> studentList = new List<Student>(); Student s = new Student(); s.Name = &qu ...

  5. java反编译工具jad

    下好以后解压就可以用了,软件就只有一个exe文件和一个帮助文件.在众多的JAVA反编译工具中,有几种非常著名的工具使用了相同的核心引擎——JAD,其中主要包括:FrontEnd Plus.mDeJav ...

  6. 12. KEY_COLUMN_USAGE

    12. KEY_COLUMN_USAGE KEY_COLUMN_USAGE表描述哪些键列具有约束. KEY_COLUMN_USAGE表有以下列: CONSTRAINT_CATALOG :约束所属目录的 ...

  7. c++_加法变乘法

    加法变乘法 我们都知道:1+2+3+ ... + 49 = 1225现在要求你把其中两个不相邻的加号变成乘号,使得结果为2015 比如:1+2+3+...+10*11+12+...+27*28+29+ ...

  8. @RestController 与 @Controller 注解区别

    文章来源:https://www.cnblogs.com/hello-tl/p/9202658.html @RestController注解相当于@ResponseBody + @Controller ...

  9. python_函数递归

    函数递归 函数递归:函数的递归调用,即在函数调用的过程中,又直接或间接地调用了函数本身 # import sys # print(sys.getrecursionlimit()) # sys.setr ...

  10. c++值传递和引用及指针传递区别

    以下程序各有何问题? ***************************************************************************************** ...