首页 > 其他 > 详细

优先队列+模拟-Fox and Number Game

时间:2014-05-07 07:19:08      阅读:412      评论:0      收藏:0      [点我收藏+]

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

bubuko.com,布布扣大意:每个测试用例是一个数组。找出xi和xj,(xi>xj),做运算令xi=xi-xj。可以做若干组这样的运算,使得最后的数组和最小。输出此和。

分析:用优先队列,每次找出最大的和次大的,处理后再加入此队列。注意多个相同的xi这种情况!

优先队列+模拟-Fox and Number Game,布布扣,bubuko.com

优先队列+模拟-Fox and Number Game

原文:http://blog.csdn.net/chuchus/article/details/25076261

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!