码迷,mamicode.com
首页 > 其他好文 > 详细

bzoj4302 Hdu 5301 Buildings

时间:2017-06-10 20:22:26      阅读:170      评论:0      收藏:0      [点我收藏+]

标签:hdu   php   就会   get   div   pre   signed   std   build   

传送门: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

 

bzoj4302 Hdu 5301 Buildings

标签:hdu   php   就会   get   div   pre   signed   std   build   

原文地址:http://www.cnblogs.com/galaxies/p/bzoj4302.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!