codeforces-Fox and Number Game
题目地址:http://codeforces.com/contest/389/problem/A
Time Limit: 1000ms
Fox Ciel is playing a game with numbers now.
Ciel has n positive integers: x1, x2, ..., xn. She can do the following operation as many times as needed: select two different indexes i and j such that xi > xj hold, and then apply assignment xi = xi - xj. The goal is to make the sum of all numbers as small
as possible.
Please help Ciel to find this minimal sum.
Input
The first line contains an integer n (2?≤?n?≤?100). Then the second line contains n integers: x1, x2, ..., xn (1?≤?xi?≤?100).
Output
Output a single integer — the required minimal sum.
Sample Input
3
2 4 6
5
45 12 27 30 18
4
1 1 2 2
2
1 2
Sample Output
6
15
4
2
大意:每个测试用例是一个数组。找出xi和xj,(xi>xj),做运算令xi=xi-xj。可以做若干组这样的运算,使得最后的数组和最小。输出此和。
分析:用优先队列,每次找出最大的和次大的,处理后再加入此队列。注意多个相同的xi这种情况!
优先队列+模拟-Fox and Number Game