您的位置:首页 > 产品设计 > UI/UE

hdu 5301 Buildings

2015-07-24 16:56 393 查看
题意:在一个n*m的矩形中,要放置很多小矩形,每个矩形必须与大矩形的边界相接触,其中有一块1*1的必须空着,他的坐标是x,y。现在问放置的小矩形面积最大值最少是多少?

分析:因为每个小矩形要和边界互相接触,所以每个小矩形都是形如1*a这样的矩形,这样才能保证面积最小,在没有空着的矩形的情况下,最小的矩形面积肯定是1*(n+1)/2,

n < m;但是若放置了一个空的1*1的矩形,那么受影响的只有那个矩形所在的一行和一列。

以下附上代码:

#include <algorithm>
#include <iostream>
#include <sstream>
#include <fstream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cctype>
#include <cmath>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

int n,m;
int x,y;

int main()
{
while(scanf("%d%d%d%d",&n,&m,&x,&y) != EOF){
if(n > m) {
swap(n,m);
swap(x,y);
}
if(n == 1){
printf("1\n");
}
else if(n == m && (n & 1) && x == y && y == (m+1)/2){
printf("%d\n",n/2);
}
else{
int up = x-1;
int down = n-x;
int left = y;
int right = m-y+1;
if(min(left,right) > (n+1)/2 && x != (n+1)/2){
printf("%d\n",min(max(up,down),min(left,right)));
}
else
printf("%d\n",(n+1)/2);
}
}
return 0;
}

/*
5 5 3 3
2
5 5 3 2
3
1 100 1 50
1
6 9 2 4
4
5 9 2 3
3
3 5 2 3
2
*/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: