Hihocoder #1042: Happy enclosure

Source: Internet
Author: User
Tags time limit

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

Obviously l the larger the area of coverage, so this problem should be the circumference of L when enumerating all the area.

The main consideration is to consider three kinds of situations:

1. Enclosure and reservoir no overlapping parts

2. A vertex of a reservoir in enclosure

3. The four vertices of the reservoir are in enclosure


It is possible to transform the reservoir into the upper-right corner of the grassland through coordinate transformation.

According to the coordinates of the reservoir center, the reservoir is located on the upper left, upper right, lower left or lower right.


For the conversion of reservoir coordinates

int L1, R1, T1, B1;
	if (L + R <= m &&t + b <= N)   //lower left corner
	{
		L1 = m-r;
		R1 = m-l;
		T1 = n-b;
		B1 = n-t;
	}
	else if (L + R >= m &&t + b <= N)  //lower right corner
	{
		L1 = l;
		R1 = r;
		T1 = n-b;
		B1 = n-t;
	}
	else if (L + R <= m &&t + b >= N)  //upper left corner
	{
		L1 = m-r;
		R1 = m-l;
		T1 = t;
		B1 = b;
	}

can be simplified into:

int L1, R1, T1, B1;
	L1 = l;
	R1 = r;
	T1 = t;
	B1 = b;
	if (L + R <= m)   
	{
		L1 = m-r;
		R1 = m-l;
	}
	if (t + b <= N)
	{
		T1 = n-b;
		B1 = n-t;
	}

The complete procedure is as follows:

#include <iostream> using namespace std;
	int main () {int n, m, L, L, R, T, B;
	CIN >> n >> m >> L;
	CIN >> L >> R >> b >> t;
		if (L >= 2 * (M + N)) {cout << m*n-(r-l) * (t-b) << Endl;
	return 0;
	int L1, R1, T1, B1;
	L1 = l;
	R1 = r;
	T1 = t;
	B1 = b;
		if (L + R <= m) {L1 = m-r;
	R1 = m-l;
		} if (T + b <= N) {t1 = N-b;
	B1 = n-t;
	int ans = 0;
		for (int i = 1; i < L/2 && i <= m. i++) {for (int j = 1; J <= L/2-i&&j <= N; j +)
			{if (i <= L1 | | J <= b1) ans = ans >i*j? ans:i*j; else if (i > L1 && i <= R1 && J > B1 && J <= t1) ans = ans > i*j-(I-L1) * (j -B1)?
			Ans:i*j-(I-L1) * (J-B1); else if (i >= r1&&j >= t1) ans = ans > i*j-(r-l) * (t-b)?
			Ans:i*j-(r-l) * (t-b);
		else continue;
	} cout << ans << endl; System"Pause");
return 0;
 }


(づ ̄3 ̄) Old





Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.