数学 HDOJ 5301 Buildings

 

题目传送门

 1 /*
 2    题意:n*m列的矩阵,删除一个格子x,y。用矩形来填充矩阵。且矩形至少有一边是在矩阵的边缘上。
 3    求满足条件的矩形填充方式中面积最大的矩形,要使得该最大矩形的面积最小。   
 4    分析:任何矩形都可以分为宽度为1的小矩形,所以只考虑矩形的可以的最小长度即可。 
 5    讨论方法:这里   (我不会。。。)
 6  */
 7 #include <cstdio>
 8 #include <algorithm>
 9 #include <cstring>
10 using namespace std;
11 typedef long long ll;
12 
13 int main(void)  {       //HDOJ 5301 Buildings
14     ll n, m, x, y;
15     while (scanf ("%I64d%I64d%I64d%I64d", &n, &m, &x, &y) == 4) {
16         if (n > m)  {
17             swap (n, m);    swap (x, y);
18         }
19         if (x > n - x + 1)  {
20             x = n - x + 1;
21         }
22         if (y > m - y + 1)  {
23             y = m - y + 1;
24         }
25         ll hm = (m + 1) / 2, hn = (n + 1) / 2;
26         ll ans = min (hm, hn);
27         if (m == n) {
28             if (m % 2 == 1) {
29                 if (x == hn && y == hm) ans--;
30             }
31         }
32         else    {
33             ll t = min (y, n - x);
34             ans = max (ans, t);
35             ans = min (ans, hm);
36         }
37         printf ("%I64d\n", ans);
38     }
39 
40     return 0;
41 }

 

posted @ 2015-07-23 21:04  Running_Time  阅读(159)  评论(0编辑  收藏  举报