Created
October 7, 2017 09:45
-
-
Save chermehdi/dd798804a8d6e94cdbe6c41270e6c6ce to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.OutputStream; | |
import java.io.IOException; | |
import java.io.InputStream; | |
import java.io.PrintWriter; | |
import java.io.InputStreamReader; | |
import java.math.BigDecimal; | |
import java.util.StringTokenizer; | |
import java.io.BufferedReader; | |
import java.io.InputStream; | |
/** | |
* @author MaxHeap | |
*/ | |
public class Sewing { | |
public static void main(String[] args) { | |
InputStream inputStream = System.in; | |
OutputStream outputStream = System.out; | |
FastReader in = new FastReader(inputStream); | |
PrintWriter out = new PrintWriter(outputStream); | |
Sewing solver = new Sewing(); | |
solver.solve(1, in, out); | |
out.close(); | |
} | |
static class Sewing { | |
public void solve(int testNumber, FastReader in, PrintWriter out) { | |
int tc = 100; | |
while (tc-- > 0) { | |
int n = in.nextInt(); | |
double a = in.nextDouble(), b = in.nextDouble(); | |
Pair<Double, Double>[] pieces = new Pair[n]; | |
pieces[0] = new Pair<>(b, a / 2.0); | |
for (int i = 1; i < n; i++) { | |
double lastWidth = pieces[i - 1].getSecond(); | |
double lastLength = pieces[i - 1].getFirst(); | |
pieces[i] = new Pair<>(lastWidth, lastLength / 2.0); | |
} | |
double[] count = new double[n]; | |
for (int i = 0; i < n; i++) count[i] = (double) in.nextInt(); | |
double need = 1.0, ans = 0.0; | |
// ArrayList<Pair<Double, Double>> used = new ArrayList<>(); | |
for (int i = 0; i < n; i++) { | |
if (need <= 0) { | |
break; | |
} | |
ans += need * pieces[i].getFirst(); | |
need = need * 2.0 - count[i]; | |
} | |
if (need > 0) { | |
out.println("impossible"); | |
} else { | |
String[] ret = (new BigDecimal(ans).setScale(6, BigDecimal.ROUND_HALF_UP).toString() + "").split("\\."); | |
while (ret[1].length() < 6) ret[1] = ret[1] + "0"; | |
out.println(ret[0] + "." + ret[1]); | |
} | |
} | |
} | |
} | |
static class FastReader { | |
BufferedReader reader; | |
StringTokenizer st; | |
public FastReader(InputStream stream) { | |
reader = new BufferedReader(new InputStreamReader(stream)); | |
st = null; | |
} | |
public String next() { | |
while (st == null || !st.hasMoreTokens()) { | |
try { | |
String line = reader.readLine(); | |
if (line == null) { | |
return null; | |
} | |
st = new StringTokenizer(line); | |
} catch (Exception e) { | |
throw new RuntimeException(); | |
} | |
} | |
return st.nextToken(); | |
} | |
public int nextInt() { | |
return Integer.parseInt(next()); | |
} | |
public double nextDouble() { | |
return Double.parseDouble(next()); | |
} | |
} | |
static class Pair<E, V> implements Comparable<Pair<E, V>> { | |
private E first; | |
private V second; | |
public Pair() { | |
} | |
public Pair(E first, V v) { | |
this.first = first; | |
this.second = v; | |
} | |
public E getFirst() { | |
return first; | |
} | |
public V getSecond() { | |
return second; | |
} | |
public int compareTo(Pair<E, V> o) { | |
Comparable<E> ce = (Comparable<E>) first; | |
Comparable<V> cv = (Comparable<V>) second; | |
if (cv.compareTo(o.getSecond()) == 0) { | |
return ce.compareTo(o.getFirst()); | |
} | |
return cv.compareTo(o.getSecond()); | |
} | |
public String toString() { | |
return "<" + first + ", " + second + ">"; | |
} | |
public boolean equals(Object o) { | |
Pair<E, V> p = (Pair<E, V>) o; | |
return first.equals(p.getFirst()) && second.equals(p.getSecond()); | |
} | |
public int hashCode() { | |
int result = first.hashCode(); | |
result = 31 * result + second.hashCode(); | |
return result; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment