-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathA.cpp
More file actions
73 lines (66 loc) · 1.45 KB
/
A.cpp
File metadata and controls
73 lines (66 loc) · 1.45 KB
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
#include <iostream>
#include <set>
#include <cmath>
using namespace std;
int N, L, W, k, size, opt;
double total;
multiset<int> v;
multiset<int>::iterator it, it2;
int main() {
cin >> N;
cin >> L >> W;
for (int i = 1; i <= N; ++i) {
cin >> k;
v.insert(k);
}
total = 0;
size = L / ((N - 4) / 2 + 1);
//cout << size << endl;
for(int i = 0; i < 2; ++i){
it = v.lower_bound(0);
if (i == 0) total += *it; else total += sqrt((*it) * (*it) + W * W);
v.erase(it);
}
for(int i = 0; i < 2; ++i){
it = v.upper_bound(L);
it--;
//cout << *it << ' ' << sqrt((L - *it) * (L - *it) + W * W) << endl;
if (i == 0) total += L - *it; else total += sqrt((L - *it) * (L - *it) + W * W);
v.erase(it);
}
// cout << total << endl;
N -= 4;
int tmp = size;
for (int i = 1; i <= N/2; ++i) {
/// Left Side
it = v.lower_bound(size);
it2 = v.upper_bound(size);
it2--;
//cout << *it << " " << *it2 << endl;
if(abs(size - *it2) > abs(size - *it)){
opt = abs(size - *it);
v.erase(it);
} else{
opt = abs(size - *it2);
v.erase(it2);
}
total += opt;
////
/// Right Side
it = v.lower_bound(size);
it2 = v.upper_bound(size);
it2--;
//cout << *it << " " << *it2 << endl;
if(abs(size - *it2) > abs(size - *it)){
opt = abs(size - *it);
v.erase(it);
} else{
opt = abs(size - *it2);
v.erase(it2);
}
total += sqrt(opt * opt + W * W);
////
size += tmp;
}
printf("%.8lf", total);
}