結果
| 問題 | No.68 よくある棒を切る問題 (2) |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-07-05 19:22:24 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 1,511 ms / 5,000 ms |
| コード長 | 2,115 bytes |
| 記録 | |
| コンパイル時間 | 4,721 ms |
| コンパイル使用メモリ | 79,836 KB |
| 実行使用メモリ | 80,492 KB |
| 最終ジャッジ日時 | 2024-10-12 20:22:31 |
| 合計ジャッジ時間 | 27,184 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 10 |
ソースコード
import java.io.*;
import java.util.*;
public class Main_yukicoder68 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Printer pr = new Printer(System.out);
int n = sc.nextInt();
// int[] l = new int[n];
PriorityQueue<Pair> pq = new PriorityQueue<>(n);
for (int i = 0; i < n; i++) {
// l[i] = sc.nextInt();
pq.add(new Pair(sc.nextInt(), 1));
}
double[] ans = new double[500_000 + 1];
for (int i = 1; i <= 500_000; i++) {
Pair e = pq.remove();
ans[i] = (double)e.a / e.b;
e.b++;
pq.add(e);
}
int q = sc.nextInt();
for (int i = 0; i < q; i++) {
int k = sc.nextInt();
pr.printf("%.10f\n", ans[k]);
}
pr.close();
sc.close();
}
private static class Pair implements Comparable<Pair> {
int a;
int b;
Pair(int a, int b) {
this.a = a;
this.b = b;
}
@Override
public int compareTo(Pair o) {
double tmp1 = (double)a / b;
double tmp2 = (double)o.a / o.b;
if (tmp1 == tmp2) {
return Integer.compare(this.b, o.b);
}
return Double.compare(tmp2, tmp1);
}
}
@SuppressWarnings("unused")
private static class Scanner {
BufferedReader br;
Iterator<String> it;
Scanner (InputStream in) {
br = new BufferedReader(new InputStreamReader(in));
}
String next() throws RuntimeException {
try {
if (it == null || !it.hasNext()) {
it = Arrays.asList(br.readLine().split(" ")).iterator();
}
return it.next();
} catch (IOException e) {
throw new IllegalStateException();
}
}
int nextInt() throws RuntimeException {
return Integer.parseInt(next());
}
long nextLong() throws RuntimeException {
return Long.parseLong(next());
}
float nextFloat() throws RuntimeException {
return Float.parseFloat(next());
}
double nextDouble() throws RuntimeException {
return Double.parseDouble(next());
}
void close() {
try {
br.close();
} catch (IOException e) {
// throw new IllegalStateException();
}
}
}
private static class Printer extends PrintWriter {
Printer(PrintStream out) {
super(out);
}
}
}