fork download
  1. import java.io.OutputStream;
  2. import java.io.FilenameFilter;
  3. import java.util.Locale;
  4. import java.io.FileOutputStream;
  5. import java.io.IOException;
  6. import java.io.FileInputStream;
  7. import java.io.File;
  8. import java.io.InputStream;
  9. import java.io.PrintWriter;
  10. import java.util.StringTokenizer;
  11. import java.io.IOException;
  12. import java.io.BufferedReader;
  13. import java.io.InputStreamReader;
  14. import java.io.InputStream;
  15.  
  16. /**
  17.  * Built using CHelper plug-in
  18.  * Actual solution is at the top
  19.  *
  20.  * @author Hieu Le
  21.  */
  22. public class Main {
  23. public static void main(String[] args) {
  24. Locale.setDefault(Locale.US);
  25. InputStream inputStream;
  26. try {
  27. final String regex = "C-(small|large).*[.]in";
  28. File directory = new File(".");
  29. File[] candidates = directory.listFiles(new FilenameFilter() {
  30. public boolean accept(File dir, String name) {
  31. return name.matches(regex);
  32. }
  33. });
  34. File toRun = null;
  35. for (File candidate : candidates) {
  36. if (toRun == null || candidate.lastModified() > toRun.lastModified())
  37. toRun = candidate;
  38. }
  39. inputStream = new FileInputStream(toRun);
  40. } catch (IOException e) {
  41. throw new RuntimeException(e);
  42. }
  43. OutputStream outputStream;
  44. try {
  45. outputStream = new FileOutputStream("c.out");
  46. } catch (IOException e) {
  47. throw new RuntimeException(e);
  48. }
  49. InputReader in = new InputReader(inputStream);
  50. PrintWriter out = new PrintWriter(outputStream);
  51. TaskC solver = new TaskC();
  52. int testCount = Integer.parseInt(in.next());
  53. for (int i = 1; i <= testCount; i++)
  54. solver.solve(i, in, out);
  55. out.close();
  56. }
  57.  
  58. static class TaskC {
  59. private static final double EPS = 1e-7;
  60.  
  61. public void solve(int testNumber, InputReader in, PrintWriter out) {
  62. int nCores = in.nextInt();
  63. int target = in.nextInt();
  64. double units = in.nextDouble();
  65. double[] probs = new double[nCores];
  66. for (int i = 0; i < nCores; ++i)
  67. probs[i] = in.nextDouble();
  68.  
  69. double low = 0.0, high = 1.0;
  70. for (int i = 0; i < 200; ++i) {
  71. double mid = (low + high) / 2;
  72. if (validate(probs, mid, units))
  73. low = mid;
  74. else
  75. high = mid;
  76. }
  77.  
  78. double result = 1.0;
  79. for (double prob : probs)
  80. result *= Math.max(prob, low);
  81. out.printf("Case #%d: %.7f\n", testNumber, result);
  82. }
  83.  
  84. private boolean validate(double[] probs, double floor, double units) {
  85. double required = 0;
  86. for (double p : probs) {
  87. if (p < floor - EPS)
  88. required += floor - p;
  89. }
  90. return required - units <= EPS;
  91. }
  92.  
  93. }
  94.  
  95. static class InputReader {
  96. private BufferedReader reader;
  97. private StringTokenizer tokenizer;
  98. private static final int BUFFER_SIZE = 32768;
  99.  
  100. public InputReader(InputStream stream) {
  101. reader = new BufferedReader(
  102. new InputStreamReader(stream), BUFFER_SIZE);
  103. tokenizer = null;
  104. }
  105.  
  106. public String next() {
  107. while (tokenizer == null || !tokenizer.hasMoreTokens()) {
  108. try {
  109. tokenizer = new StringTokenizer(reader.readLine());
  110. } catch (IOException e) {
  111. throw new RuntimeException(e);
  112. }
  113. }
  114. return tokenizer.nextToken();
  115. }
  116.  
  117. public int nextInt() {
  118. return Integer.parseInt(next());
  119. }
  120.  
  121. public double nextDouble() {
  122. return Double.parseDouble(next());
  123. }
  124.  
  125. }
  126. }
Runtime error #stdin #stdout #stderr 0.05s 4386816KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Exception in thread "main" java.lang.NullPointerException
	at java.io.FileInputStream.<init>(FileInputStream.java:130)
	at Main.main(Main.java:39)