HDU 5301 Buildings(2015多校第二场)

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 ,
where each apartment is a smaller rectangle with dimensions  located
inside. For each apartment, its dimensions can be different from each other. The number  and  must
be integers.

Additionally, the apartments must completely cover the floor without one  square
located on .
The apartments must not intersect, but they can touch.

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  testcases.

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

Hint

Case 1 :

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

Case 2:

You can split the floor into three  apartments and two  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

2015
Multi-University Training Contest 2

解题思路:

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

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

#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;
}

时间: 2024-10-10 18:58:13

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

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

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5301 题意:给你一个n*m的矩形,可以分成n*m个1*1的小矩形,再给你一个坐标(x,y),表示黑格子在n*m矩形中的位置,黑格子占一个1*1的小矩形的空间,用各种矩形去填充n*m矩形,(x,y)位置不能填,且每个去填充的小矩形都有一边是靠着n*m矩形的外框,求这些填充的小矩形在最小大小情况下的面积最大的矩形面积. 思路:要是填充的矩形大小最小,那么靠近边框的长度一定为1,所以只要判断在矩形内部的长

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

题目链接:http://acm.hdu.edu.cn/listproblem.php?vol=44 题意:给你n个n,如果能在n-1次运算之后(加减乘除)结果为24的输出n-1次运算的过程,如果不能输出-1. 思路:乍看起来,没什么规律,但是可以想象的是(n+n+n+n)/n=4,(n+n+n+n+n+n)/n=6,(n-n)*n*n*·····*n=0所以在n大于15的时候结果基本是固定的,只要对小于15的数一一输出就行(但是这题真是无语,算这种题目真是累,脑洞啊~~) 代码: 1 #incl

HDU 5305 Friends(2015多校第二场 dfs + 剪枝)

Friends Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 552    Accepted Submission(s): 253 Problem Description There are  people and  pairs of friends. For every pair of friends, they can choos

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

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5305 题意:给你n个人,m条关系,关系可以是online也可以是offline,让你求在保证所有人online关系的朋友和offline关系的朋友相等的情况下,这样的情况有多少种. 思路:因为online关系和offline关系的人数相等,而且m最多才28,所以只要枚举每个人的一半的关系是否符合要求即可,而且根据题意m是奇数或者有一个人的总关系为奇数那么就没有符合要求的情况,这样可以排除很多情况.

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 K (Java/Others) Total Submission(s): 485    Accepted Submission(s): 191 Special Judge Problem Description Recently Rikka falls in love with an old bu

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

Delicious Apples Time Limit: 5000/3000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others) Total Submission(s): 321    Accepted Submission(s): 95 Problem Description There are  apple trees planted along a cyclic road, which is  metres lon

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

Assignment Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 627    Accepted Submission(s): 318 Problem Description Tom owns a company and he is the boss. There are n staffs which are numbered fr

2015多校第二场 1004( Delicious Apples )

题意:有一条圆形的路,你的仓库在0点,这条路长l,然后有n个苹果树,每个数的坐标是xi(顺时针),每棵树上有ai个苹果.你有个篮子,能装k个苹果,问你用这个篮子将所有苹果装回仓库所走的最短路为多少? 1≤n,k≤105,ai≥1,a1+a2+...+an≤105 1≤L≤109 0≤x[i]≤L 请特别注意上面的苹果个数的条件.因为我的学长 就是从这个条件成功做出了这道题,orz! 因为苹果数不超过10^5,所以将每个苹果当作点. 用一个数组pos记录每个苹果距0点的距离,排序后,然后就可以用另

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

依据题意的话最多32条边,直接暴力的话 2 ^ 32肯定超时了.我们能够分两次搜索时间复杂度降低为 2 * 2  ^ 16 唯一须要注意的就是对眼下状态的哈希处理. 我採用的是 十进制表示法 跑的还是比較快的,可能是用STL函数的原因添加了一些常数复杂度. #include<map> #include<vector> #include<cstdio> #include<cstring> #include<algorithm> using name