B-Happy Enclosure
Waking up, little hi travels back to ancient times. Due to the broken enemy meritorious, Khan reward small hi can be on the enemy's grassland in happy enclosure: a day riding around the grassland is small hi pasture. But what makes little h headache is that there is a rotten pond on the enemy's prairie. Little hi can not ride into the stinking pond, and even if the little hi riding path around the smelly pond, little hi cattle and horses can not be grazing in the smelly pond.
To be more scientifically enclosure, little hi simplifies and abstracts this problem: (1) The enemy's grassland is a nxm square matrix, (2) The path of horseback riding is a closed line along the edge of the square, (3) The smelly pond is a rectangle in the matrix, (4) The path circumference of the horse is not more than L. Little hi wants to know how much area of grassland you can best circle (the area of a stinking pond is not counted).
As shown in Figure 1 is a valid path; Figure 2 is also a valid path, but the area of the steppe is 0; Figure 3 is not a valid path because it is not closed; Figure 4 is not a valid path because it crosses the pond. Input
First line 3 integers: N, M, L (1 <= N, M <=, 1 <= L <= 400)
The second line is 4 integers: l, r, T, B (0 <= l < r <= m, 0 <= t < b <= N) represent the left, right, upper, and lower boundary coordinates of the reservoir. Output
Small Hi maximum lap area Sample Input
4 4 8
1 3 1 3
Sample Output
3
"parsing"
first say positive solution, which is based on the circumference of the input of L, from large to small to reduce, and in the order of small to large to enumerate the length or width, and then calculate the corresponding width or length, and then according to different circumstances to determine, until the maximum value found.
for ease of understanding, with the following figure:
"AC Code"
#include <cstdio> #include <iostream> #include <cstring> #include <string> #include <
Algorithm> using namespace std;
int n,m,l,l,r,t,b;
int Re (int z,int y,int s,int x) {int zmj= (y-z) * (x-s);
int Jq=max (min (y,r)-max (z,l), 0) *max (min (x,b)-max (s,t), 0);
if (min (x,b) ==b&&max (s,t) ==t&&min (y,r) ==r&&max (z,l) ==l) return ZMJ-JQ; if (min (x,b) ==b&&max (s,t) ==t&&x!=b&&s!=t) {if ((y-z) + (x-s)) *2+2* (min (y,r)-max (z,l))
; =l) return ZMJ-JQ;
return 0; } if (min (y,r) ==r&&max (z,l) ==l&&y!=r&&z!=l) {if ((y-z) + (x-s)) *2+2* (min (x,b)-max (s)
T)) <=l return ZMJ-JQ;
return 0;
return ZMJ-JQ;
int main () {scanf ("%d%d%d", &n,&m,&l);
scanf ('%d%d%d%d ', &l,&r,&t,&b);
if (2* (n+m) <=l) {printf ("%d\n", n*m-((r-l) * (B-T)));
return 0;
int ans=0; for (; l>=4; L--) {for (int i=max (l/2-m,1); i<=n&&i<l/2;i++) {int j=l/2-i;
Ans=max (Ans,re (0,j,0,i));
Ans=max (Ans,re (0,j,n-i,n));
Ans=max (Ans,re (m-j,m,0,i));
Ans=max (Ans,re (m-j,m,n-i,n));
} printf ("%d\n", ans);
}