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. 比特币 3角对冲python代码

    3角对冲原理 基础货币 base, 兑换货币 quote, 中间货币 mid. 市场分为3个市场 p3: base_quote p2: quote_mid p1: quote_mid 代码逻辑 1, ...

  2. 宝塔apache配置

    apache配置 <VirtualHost *:80> ServerAdmin webmaster@example.com DocumentRoot "/www/wwwroot/ ...

  3. 单链表 C语言 学习记录

    概念 链接方式存储 链接方式存储的线性表简称为链表(Linked List). 链表的具体存储表示为: 用一组任意的存储单元来存放线性表的结点(这组存储单元既可以是连续的,也可以是不连续的). 链表中 ...

  4. 实验:iscsi共享存储

    实验名称: iscsi共享存储 实验环境: 我们需要准备一个磁盘,对于这个磁盘我们需要使用,将这个磁盘空间共享给iscsi客户端: 实验需求: 我们这里使用两台服务器来实现iscsi共享存储: 1.指 ...

  5. 深刻理解下js的prototype

    参考 http://aralejs.org/class/docs/competitors.html, http://www.iteye.com/topic/248933,http://www.cnbl ...

  6. 命令行可以执行python脚本,jenkins里执行报错:cannot find Chrome binary

    “selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Chrome binary”这个 ...

  7. navicat不同数据库数据传输

    复制fo的t_fo_account表结构和数据到base库 结果

  8. 大数据学习——redis安装

    用源码工程来编译安装 / 到官网下载最新stable版 / 解压源码并进入目录 .tar.gz -C ./redis-src/ / make 如果报错提示缺少gcc,则安装gcc : yum inst ...

  9. asp.net 页面缓存、数据缓存

    页面缓存,webform框架的aspx页面,服务器引擎生成的页面可以被缓存.

  10. POJ-1797Heavy Transportation,最短路变形,用dijkstra稍加修改就可以了;

    Heavy Transportation Time Limit: 3000MS   Memory Limit: 30000K          Description Background  Hugo ...