bzoj4302 Hdu 5301 Buildings

传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=4302

【题解】

出自2015多校-学军

题意大概是给出一个n*m的格子有一个格子(x,y)是坏的,用一些矩形覆盖没有坏的格子,使得每个矩形都有一面靠着边界。求最大的矩形的面积最小。

稍微分析就会发现肯定是1*x的矩形最优,因为如果是2*x可以分成2个1*x。

那么我们先把矩形转转位置,使得n<=m,且(x,y)在左上角。

矩形内没有坏点,显然方案是(n+1)/2

我们画个图,黑色的那个是坏点,我们发现要处理坏点有2种方法

(其中红色的为处理坏点的,绿色的为正常的答案)

显然是这两种方案中选一个花费最小的。

答案就是max((n+1)/2, min(n-x,y))

有一种特殊情况需要特判就是:n=m,且坏点在正方形正中心,答案是x-1

# include <stdio.h>
# include <string.h>
# include <iostream>
# include <algorithm>
// # include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const int M = 5e5 + 10;
const int mod = 1e9+7;

# define RG register
# define ST static

int n, m, x, y, ans;

int main() {
    while(~scanf("%d%d%d%d", &n, &m, &x, &y)) {
        if(n > m) swap(n, m), swap(x, y);
        x = min(x, n-x+1), y = min(y, m-y+1);
        if(n == m && (n&1) && x == (n+1)/2 && x == y) ans = x-1;
        else ans = max((n+1)/2, min(n-x, y));
        printf("%d\n", ans);
    }
    return 0;
}
View Code

 

转载于:https://www.cnblogs.com/galaxies/p/bzoj4302.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值