Gym 100269G-Garage

本文探讨了如何在限定的空间内放置尽可能少的矩形车库,以满足合同要求的最大数量限制。通过算法计算最少所需的车库数量,确保无法再添加额外的车库。

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

Problem G. Garage
Input file: garage.in
Output file: garage.out
Time limit: 2 seconds
Memory limit: 256 megabytes
Wow! What a lucky day! Your company has just won a social contract for building a garage complex.
Almost all formalities are done: contract payment is already transferred to your account.
So now it is the right time to read the contract. Okay, there is a sandlot in the form of W × H rectangle
and you have to place some garages there. Garages are w × h rectangles and their edges must be parallel
to the corresponding edges of the sandlot (you may not rotate garages, even by 90◦
). The coordinates of
garages may be non-integer.
You know that the economy must be economical, so you decided to place as few garages as possible.
Unfortunately, there is an opposite requirement in the contract: placing maximum possible number of
garages.
Now let’s see how these requirements are checked… The plan is accepted if it is impossible to add a new
garage without moving the other garages (the new garage must also have edges parallel to corresponding
sandlot edges).
这里写图片描述
Time is money, find the minimal number of garages that must be ordered, so that you can place them
on the sandlot and there is no place for an extra garage.
Input
The only line contains four integers: W, H, w, h — dimensions of sandlot and garage in meters. You may
assume that 1 ≤ w ≤ W ≤ 30 000 and 1 ≤ h ≤ H ≤ 30 000.
Output
Output the optimal number of garages.
Examples
garage.in garage.out
11 4 3 2 2
10 8 3 4 2
15 7 4 2 4
The plan on the first picture is accepted and optimal for the first example. Note that a rotated (2 × 3)
garage could be placed on the sandlot, but it is prohibited by the contract.

题意:问能放几个停车位将沙地占满,使得所放的停车位最少。

代码:

#include <cstdio>
#include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;
int main (void)
{
    //freopen
    //freopen
    int X,Y,x,y;
    scanf("%d %d %d %d",&X,&Y,&x,&y);
    int xx,yy;
    xx=2*x;
    yy=2*y;
    int cntx=X/xx;
    int cnty=Y/yy;
//  printf("%d %d__\n",cntx,cnty);
    if(X%xx>=x)
        cntx++;
//      printf("cntx=%d\n",cntx);
    if(Y%yy>=y)
        cnty++;
//  printf("cnty=%d\n",cnty);
    printf("%d\n",cntx*cnty);
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值