Time limit: 10000ms single point time limit: 1000ms memory limit: 256MB
Description
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 hi 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
Analysis: This problem can not be thought of, is to simplify the complex problem, you can see that there are many kinds of coverage of the situation, but is not covered, covering a corner, two, full coverage. When you cover two corners, you can see that the edges are missing. This must make the area shrink again, otherwise the perimeter is not enough, can not be considered. While covering a corner of the perimeter can be along the pond again, just enough circumference, but is a small area. The full coverage of the words is obvious.
The difficulty is how to achieve the idea.
Here is a transformation of the idea that the pond in the grassland is actually a focus (position), and for the sake of unification, we put all the reservoir bias is unified in the lower right corner of the position, and then the enumeration can be. The specific code is as follows:
#include <iostream> #include <stdio.h> using namespace std;
int main () {int n,m,l,l,r,t,b,l1,r1,t1,b1;
int ans=0;
scanf ("%d%d%d", &n,&m,&l);
scanf ("%d%d%d%d", &l,&r,&t,&b); if (l+r<=m&&t+b<=n)//This indicates which side is biased.
Validate l1=m-r by taking instance;
R1=m-l;
T1=n-b;
B1=n-t;
else if (l+r<=m&&t+b>n) {l1=m-r;
R1=m-l;
t1=t;
B1=b;
else if (l+r>m&&t+b<=n) {l1=l;
R1=r;
T1=n-b;
B1=n-t; }//the rest of the situation itself is already in the lower right corner. for (int i=0;i<=l/2&&i<=n;i++)//in sequence, enumerate {for (int j=0;j<=l/2&&j& lt;=m&&i+j<=l/2;j++) {if (i<=t1| |
J<=L1)//This situation is Ans=max (ans,i*j) without passing through the reservoir; if (I>T1&&I<=B1&&J>L1&&J<=R1)//happens to pass through a corner of the reservoir Ans=max (ans,i*j-(I-T1) * (J-L1))
; if (i>b1&&j>R1)//Full Coverage Ans=max (ans,i*j-(B1-T1) * (R1-L1));
} printf ("%d", ans);
return 0;
}