-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathColoringRectangle.cpp
59 lines (53 loc) · 1.37 KB
/
ColoringRectangle.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
#include<iostream>
#include<cstdio>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<string>
#include<list>
#include<deque>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<utility>
#include<sstream>
#include<cstring>
using namespace std;
class ColoringRectangle {
public:
double calc(int dia, int h) {
double r = ((double)dia) / 2.0f;
double hh = ((double)h) / 2.0f;
return sqrt(r * r - hh * hh);
}
int chooseDisks(int w, int h, vector <int> r, vector <int> b) {
sort(r.rbegin(), r.rend());
sort(b.rbegin(), b.rend());
int result = 0;
int i = 0, j = 0;
bool red;
if (r[0] >= b[0])
red = true;
else
red = false;
double dist = 0;
while (dist < w) {
if (red) {
if (i >= r.size() || r[i] < h)
return -1;
dist += 2*calc(r[i++], h);
result++;
} else {
if (j >= b.size() || b[j] < h)
return -1;
dist += 2*calc(b[j++], h);
result++;
}
red = !red;
}
return result;
}
};