優先隊列+模擬-Fox and Number Game
codeforces-Fox and Number Game
題目地址:https://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這種情況!
最後更新:2017-04-03 12:56:32