F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

View Compilation Error

0_0_38584696_10684\Main.java:1: 错误: 无法推断Iterator<E>的类型参数
import java.util.Iterator; public class Main { public static void main(String[] args) { A.main(args); } } class A { public static void main(String[] args) { Input input = new Input(); Output output = new Output(); try { while (true) { int n = input.nextInt(); int m = input.nextInt(); short[] a = new short[n]; for (int i = 0; i < n; i++) a[i] = (short)input.nextInt(); RadixSort_short.sort(a); Heap_Element heap = new Heap_Element(m + 1, (x, y) -> Integer.compare(y.value, x.value), new FieldAccess_Element_int() { public int get(Element t) { return t.heapIndex; } public void set(Element t, int v) { t.heapIndex = v; } }); heap.offer(new Element(a[n - 2] + a[n - 1], n - 2, n - 1)); int low = n - 2; for (int i = 0; i < m; i++) { Element element = heap.peek(); output.append(element.value).append(' '); if (element.from == low && low > 0) { low--; heap.offer(new Element(a[low] + a[n - 1], low, n - 1)); } if (--element.to == element.from) heap.poll(); else { element.value = a[element.from] + a[element.to]; heap.increase(element); } } output.appendNewLine(); } } catch (ArrayIndexOutOfBoundsException ex) {} output.flush(); } } class Element { int value; final int from; int to; int heapIndex; Element(int value, int from, int to) { this.value = value; this.from = from; this.to = to; } } interface FieldAccess_Element_int { int get(Element t); void set(Element t, int v); } interface Function_int_Element_Element { int apply(Element arg1, Element arg2); } class Heap_Element implements Iterable<Element> { private final Element[] heap; private final Function_int_Element_Element comparator; private final FieldAccess_Element_int index; private int size; public Heap_Element(int n, Function_int_Element_Element comparator, FieldAccess_Element_int index) { heap = new Element[Integer.highestOneBit(n) << 1]; this.comparator = comparator; this.index = index; } public int size() { return size; } public Iterator<Element> iterator() { return new Iterator<>() { private int index; public boolean hasNext() { return index != size; } public Element next() { return heap[++index]; } }; } public void offer(Element e) { siftUp(++size, e); } public void decrease(Element e) { siftUp(index.get(e), e); } private void siftUp(int index, Element e) { for (int i = index, j = index >> 1; ; i = j, j >>= 1) { if (j == 0 || comparator.apply(heap[j], e) <= 0) { set(i, e); break; } else set(i, heap[j]); } } public Element poll() { Element e = heap[1]; siftDown(1, heap[size--]); return e; } public void increase(Element e) { siftDown(index.get(e), e); } private void siftDown(int index, Element e) { for (int i = index; ; ) { int left = i << 1; int right = left | 1; if (right > size) { if (left > size || comparator.apply(e, heap[left]) <= 0) set(i, e); else { set(i, heap[left]); set(left, e); } break; } else { if (comparator.apply(heap[left], heap[right]) < 0) { if (comparator.apply(heap[left], e) < 0) { set(i, heap[left]); i = left; } else { set(i, e); break; } } else { if (comparator.apply(heap[right], e) < 0) { set(i, heap[right]); i = right; } else { set(i, e); break; } } } } } private void set(int index, Element e) { heap[index] = e; this.index.set(e, index); } public Element peek() { return heap[1]; } public void remove(Element e) { for (int i = index.get(e), j = i >> 1; j != 0; i = j, j >>= 1) set(i, heap[j]); siftDown(1, heap[size--]); } public void clear() { size = 0; } } class Input { private final byte[] buffer; private int pos; public Input() { try { buffer = new byte[System.in.available() + 1]; buffer[buffer.length - 1] = '\n'; System.in.read(buffer); } catch (Exception ex) { throw new RuntimeException(ex); } } public byte[] next(int n) { while (true) { byte b = buffer[pos++]; if (b != '\n' && b != '\r') { pos--; break; } } byte[] bytes = new byte[n]; System.arraycopy(buffer, pos, bytes, 0, n); pos += n; return bytes; } public byte[] next() { int from; while (true) { byte b = buffer[pos++]; if (b != ' ' && b != '\n' && b != '\r') { from = pos; break; } } byte[] bytes; while (true) { byte b = buffer[pos++]; if (b == ' ' || b == '\n') { bytes = new byte[pos - from]; break; } else if (b == '\r') { bytes = new byte[pos++ - from]; break; } } System.arraycopy(buffer, from - 1, bytes, 0, bytes.length); return bytes; } public byte[] nextLine() { int from = pos; byte[] bytes; while (true) { byte b = buffer[pos++]; if (b == '\n') { bytes = new byte[pos - from - 1]; break; } else if (b == '\r') { bytes = new byte[pos++ - from - 1]; break; } } System.arraycopy(buffer, from, bytes, 0, bytes.length); return bytes; } public byte nextChar() { while (true) { byte b = buffer[pos++]; if (b != ' ' && b != '\n' && b != '\r') return b; } } public int nextInt() { int n; boolean positive; while (true) { byte b = buffer[pos++]; if (b == '-') { positive = false; n = buffer[pos++] - '0'; break; } else if (b >= '0' && b <= '9') { positive = true; n = b - '0'; break; } } while (true) { byte b = buffer[pos++]; if (b >= '0' && b <= '9') n = n * 10 + b - '0'; else { if (b == '\r') pos++; return positive ? n : -n; } } } public long nextLong() { long n; boolean positive; while (true) { byte b = buffer[pos++]; if (b == '-') { positive = false; n = buffer[pos++] - '0'; break; } else if (b >= '0' && b <= '9') { positive = true; n = b - '0'; break; } } while (true) { byte b = buffer[pos++]; if (b >= '0' && b <= '9') n = n * 10 + b - '0'; else { if (b == '\r') pos++; return positive ? n : -n; } } } public double nextDouble() { long n; boolean positive; while (true) { byte b = buffer[pos++]; if (b == '-') { positive = false; n = buffer[pos++] - '0'; break; } else if (b >= '0' && b <= '9') { positive = true; n = b - '0'; break; } } while (true) { byte b = buffer[pos++]; if (b >= '0' && b <= '9') n = n * 10 + b - '0'; else if (b == '.') break; else return positive ? n : -n; } long m = 0; long o = 1; while (true) { byte b = buffer[pos++]; if (b >= '0' && b <= '9') { m = m * 10 + b - '0'; o *= 10; } else { if (b == '\r') pos++; double d = n + (double)m / o; return positive ? d : -d; } } } public int[] nextInts(int n) { int[] ints = new int[n]; for (int i = 0; i < n; i++) ints[i] = nextInt(); return ints; } public long[] nextLongs(int n) { long[] longs = new long[n]; for (int i = 0; i < n; i++) longs[i] = nextLong(); return longs; } } class Output { private static final int BUFFER_SIZE = 1048576; private static final boolean CRLF = System.lineSeparator().equals("\r\n"); private final byte[] buffer = new byte[BUFFER_SIZE]; private int pos; public Output append(String s) { int length = s.length(); ensureCapacity(length); for (int i = 0; i < length; i++) buffer[pos++] = (byte)s.charAt(i); return this; } public Output append(byte[] bytes) { if (BUFFER_SIZE - pos < bytes.length) { flush(); if (bytes.length > BUFFER_SIZE) { System.out.write(bytes, 0, bytes.length); return this; } } for (byte b: bytes) buffer[pos++] = b; return this; } public Output append(byte[] bytes, int from, int to) { int length = to - from; if (BUFFER_SIZE - pos < length) { flush(); if (length > BUFFER_SIZE) { System.out.write(bytes, from, length); return this; } } for (int i = from; i < to; i++) buffer[pos++] = bytes[i]; return this; } public Output append(byte b) { ensureCapacity(1); buffer[pos++] = b; return this; } public Output append(char c) { return append((byte)c); } public Output append(int i) { return append(Integer.toString(i)); } public Output append(long l) { return append(Long.toString(l)); } public Output append(double d) { return append(Double.toString(d)); } public void appendNewLine() { ensureCapacity(2); if (CRLF) buffer[pos++] = '\r'; buffer[pos++] = '\n'; } public void flush() { System.out.write(buffer, 0, pos); pos = 0; } private void ensureCapacity(int n) { if (BUFFER_SIZE - pos < n) flush(); } } class RadixSort_short { private static final int BITS = 16; private static final int RADIX = 1 << BITS; private static final int MASK = RADIX - 1; private RadixSort_short() {} public static void sort(short[] a) { sort(a, 0, a.length); } public static void sort(short[] a, int from, int to) { short[] b = a.clone(); for (int i = 0; i < Short.SIZE; i += BITS) { int[] count = new int[RADIX]; for (int j = from; j < to; j++) count[(int)(b[j] >>> i & MASK)]++; count[0] += from; for (int j = 1; j < RADIX; j++) count[j] += count[j - 1]; for (int j = to - 1; j >= from; j--) a[--count[(int)(b[j] >>> i & MASK)]] = b[j]; short[] temp = a; a = b; b = temp; } int lower = from; for (int upper = to; lower < upper; ) { int mid = lower + upper >> 1; if (b[mid] < 0) upper = mid; else lower = mid + 1; } System.arraycopy(b, lower, a, from, to - lower); System.arraycopy(b, from, a, to - lower, lower - from); } }
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              


Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-17 02:58:23, Gzip enabled