-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlargestBlock_hardway.cpp
120 lines (109 loc) · 2.92 KB
/
largestBlock_hardway.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <set>
#include <string>
#include <vector>
using namespace std;
ifstream fin("largestBlock.in");
ofstream fout("largestBlock.out");
struct block
{
int r1;
int c1;
int r2;
int c2;
};
bool g(int y1, int x1, int y2, int x2, block & b)
{
if (y1 <= b.r1 && b.r1 <= y2 && x1 <= b.c1 && b.c1 <= x2)
{
return false;
}
else if (y1 <= b.r1 && b.r1 <= y2 && x1 <= b.c2 && b.c2 <= x2)
{
return false;
}
else if (y1 <= b.r2 && b.r2 <= y2 && x1 <= b.c1 && b.c1 <= x2)
{
return false;
}
else if (y1 <= b.r2 && b.r2 <= y2 && x1 <= b.c2 && b.c2 <= x2)
{
return false;
}
else if (b.r1 <= y1 && b.r2 >= y2 && x1 <= b.c1 && b.c1 <= x2)
{
return false;
}
else if (b.r1 <= y1 && b.r2 >= y2 && x1 <= b.c2 && b.c2 <= x2)
{
return false;
}
else if (b.c1 <= x1 && b.c2 >= x2 && y1 <= b.r1 && b.r1 <= y2)
{
return false;
}
else if (b.c1 <= x1 && b.c2 >= x2 && y1 <= b.r2 && b.r2 <= y2)
{
return false;
}
return true;
}
int main()
{
int testCase;
fin >> testCase;
for (int c = 1; c <= testCase; ++c)
{
int s, n;
fin >> s >> n;
vector<block> blocks(n);
for (int i = 0; i <= n - 1; ++i)
{
int a, b, c, d;
fin >> a >> b >> c >> d;
blocks[i].r1 = min(a, c);
blocks[i].c1 = min(b, d);
blocks[i].r2 = max(a, c);
blocks[i].c2 = max(b, d);
}
int maxSize = 1;
for (int y1 = 1; y1 <= s; ++y1)
{
for (int x1 = 1; x1 <= s; ++x1)
{
for (int y2 = y1; y2 <= s; ++y2)
{
for (int x2 = x1; x2 <= s; ++x2)
{
bool ok = true;
for (int i = 0; i <= n - 1; ++i)
{
if (g(y1,x1,y2,x2,blocks[i]) == false)
{
ok = false;
break;
}
}
if (ok == true)
{
int size = (y2 - y1 + 1) * (x2 - x1 + 1);
if (size > maxSize)
{
maxSize = size;
//fout << "* " << y1 << ' ' << x1 << ' ' << y2 << ' ' << x2 << '\n';
}
}
}
}
}
}
fout << maxSize << '\n';
}
return 0;
}