2018/7/17 hdu5301 训练日记1

本文探讨了一种算法问题,即如何在给定的矩形区域内,避开特定障碍物,划分出多个矩形区域(公寓),使得其中面积最大的矩形面积尽可能小。文章提供了解决方案并附带了实现代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

 

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

 

题意:要建一个n*m的大房子,其中有一个格子不能建房间。你要建若干个矩形的房间,并且每个矩形至少有一个边是房子的边界。求使面积最大的那个房间的面积最小的面积。

思路:

先考虑不能建房间的格子无影响的情况,答案是(min(m,n)+1)/2。

如果不能建房间的格子有好的影响,其实只有一种情况:n==m 且n、m为奇数且x、y就是中间的那个格子。

这种情况下答案为n/2。

如果不能建房间的格子有坏的影响,那就只会影响那一行或者那一列的房间。于是先固定n>m,这样只有第x行的格子受到影响,而且是(x,y)左右两边的格子中离左右边界最远的那个格子。于是我们枚举它向上、向下、向左或右建的最小面积。最后和(min(m,n)+1)/2取个最大值

扩展:

这种思维技巧题,如果要说扩展的话就是不太好想,感觉上有点类似于哪种铺地板的题目,不过不是很一样

代码:

#include<bits/stdc++.h>
using namespace std;
const int maxn=200010;
int n,m,k,x,y;
int a[maxn],sum[maxn];
int c[maxn],pos[maxn],l[maxn],r[maxn];
int ans,ct,cnt,tmp,flag;
char s[maxn];
int main()
{
        while(scanf("%d%d%d%d",&n,&m,&x,&y)!=EOF)
        {
                ans=0;
                flag=1;
                if(n<m)
                {
                  swap(n,m);
                  swap(x,y);
                }
                ans=(m+1)/2;
                if((n&1)&&n==m&&x==y&&y==(m+1)/2)
                        ans=n/2;
                else{
                        x=min(x,n-x+1);
                        y=max(y-1,m-y);
                        int aa=min(x,y);
                        ans=max(ans,aa);
                }
                printf("%d\n",ans);
        }
        return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值