题目1107:搬水果
2014-01-07 21:19
267 查看
import java.io.IOException; import java.io.FileReader; import java.io.BufferedReader; import java.util.Scanner; import java.util.PriorityQueue; class Main { public static final boolean DEBUG = false; public static void main(String[] args) throws IOException { Scanner cin; int n; if (DEBUG) { cin = new Scanner(new BufferedReader(new FileReader("d:\\OJ\\uva_in.txt"))); } else { cin = new Scanner(System.in); } while (cin.hasNext()) { n = cin.nextInt(); if (n == 0) break; PriorityQueue<Integer> q = new PriorityQueue<Integer>(); for (int i = 0; i < n; i++) { q.add(new Integer(cin.nextInt())); } int sum = 0; for (int i = 0; i < n - 1; i++) { int a = q.poll().intValue(); int b= q.poll().intValue(); sum += a + b; q.add(new Integer(a + b)); } while (!q.isEmpty()) { q.poll(); } System.out.println(sum); } } }
相关文章推荐
- 【九度OJ】题目1107:搬水果 解题报告
- 题目1107:搬水果 九度OJ
- 题目1107:搬水果(哈夫曼树)
- 题目1107:搬水果
- 九度题目-1107:搬水果
- 九度题目1107:搬水果
- 九度题目1107:搬水果
- 题目1107:搬水果
- 九度OJ题目1107:搬水果
- 题目1107:搬水果
- 题目1107:搬水果
- 九度 题目1107:搬水果
- 31-题目1107:搬水果
- 题目1107:搬水果
- 题目1107:搬水果
- 哈夫曼树应用——九度OJ题目1107:搬水果
- 题目1107:搬水果(哈夫曼树+快速排序+冒泡排序)
- 哈夫曼树应用——九度OJ题目1107:搬水果
- 题目1107:搬水果【哈夫曼树模型】
- 1107_搬水果