hdu5301 思维题

题目大意:给出a*b的矩阵,里面有一个坏点,求用不覆盖这个坏点的其他矩阵填满a*b的矩阵,使得其他矩阵的最大面积最小,并输出最小面积。

思路:如果在正方形中央,且边长为奇数 ,答案就是n/2;

如果是长方形,看那个坏点距离上下边界的最大值和左右边界的最小值那个更小,结果再和(n + 1) / 2取最大值即可。

#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <bitset>

using namespace std;

#define MAXN 1000005

int main()
{
    int n , m , x , y;
    while(cin >> n >> m >> x >> y)
    {
        if(n > m) swap(n , m) , swap(x , y);
        int ans =(n + 1) / 2;
        if( n == m && x == y && n%2 && x == (n + 1) / 2) ans-- ;
        else
        {
            int temp1 = max(x - 1 , n - x);   //距上下边界距离最大值
            int temp2 = min(y , m - y + 1); //左右边界距离最小值
            ans = min(temp1 , temp2);
            ans = max(ans , (n + 1) / 2);
        }
        cout << ans << endl;
    }
    return 0;
}


你可能感兴趣的:(hdu5301 思维题)