-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathSRM493-D2-1000.cpp
76 lines (72 loc) · 1.55 KB
/
SRM493-D2-1000.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
/*
Author: Ayman Salah
Category: Brute Force, Geometry
*/
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <climits>
using namespace std;
class CrouchingAmoebas {
public:
int count(vector <int> x, vector <int> y, int A, int T) {
int n = (int)x.size();
int ret = 0;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
for (int dx = -T; dx <= T; ++dx) {
for (int dy = -T; dy <= T; ++dy) {
if (abs(dx) + abs(dy) <= T)
{
int left_x = dx + x[i];
int down_y = dy + y[j];
vector<int> vals;
vals.clear();
for (int k = 0; k < n; ++k)
{
int cur = 0;
if (x[k]<left_x)
cur += left_x - x[k];
else if (x[k]>left_x + A)
cur += x[k] - left_x - A;
if (cur > T) continue;
if (y[k]<down_y)
cur += down_y - y[k];
else if (y[k]>down_y + A)
cur += y[k] - down_y - A;
if (cur > T) continue;
vals.push_back(cur);
}
int cnt = 0, rem = T;
sort(vals.begin(), vals.end());
for (int k = 0; k < vals.size(); ++k) {
if (rem - vals[k] < 0) break;
rem -= vals[k];
cnt++;
}
ret = max(ret, cnt);
}
}
}
}
}
return ret;
}
};