forked from mpfeifer1/Kattis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patha1paper.cpp
53 lines (42 loc) · 925 Bytes
/
a1paper.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
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
ll n;
cin >> n;
n--;
vector<ll> v(n);
for(auto& i : v) {
cin >> i;
}
ld totalcost = 0;
ll needed = 1;
bool enough = false;
ld longedge = pow(2.0, -3/4.0);
ld shortedge = pow(2.0, -5/4.0);
for(ll i = 0; i < v.size(); i++) {
// Calculate cost here
totalcost += needed * longedge;
swap(shortedge, longedge);
shortedge /= 2;
// Calculate paper needed now
needed *= 2;
needed -= v[i];
// Check if we have enough paper
if(needed <= 0) {
enough = true;
break;
}
}
cout << fixed;
cout.precision(9);
if(enough) {
cout << totalcost << endl;
}
else {
cout << "impossible" << endl;
}
}