Codeforces Round #228 (Div. 2), problem: (A) Fox and Number Game
2015-01-07 21:21
441 查看
Codeforces Round #228 (Div. 2), problem: (A) Fox and Number Game,题目如下:
A. Fox and Number Game
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
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 test(s)
input
output
input
output
input
output
input
output
Note
In the first example the optimal way is to do the assignment: x2 = x2 - x1.
In the second example the optimal sequence of operations is: x3 = x3 - x2, x2 = x2 - x1
意思很简单,给出n个数,执行如下操作若干次:从中任取两个数,满足,然后赋值,直到所有数的和最小。
根据题目,得出如下思路,将给出的n个数从小到大排序,为了让操作次数尽可能少,让第n个减去第n-1个,再将得
出的新数组排序,重复执行上述操作。可发现,当所有数都相等时,操作结束,此时的和最小。
题目很简单,但是演算的时候可以发现,这是在求n个数的最大公约数,所以特别将该题记录下来。代码如下:
A. Fox and Number Game
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
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 test(s)
input
2 1 2
output
2
input
3 2 4 6
output
6
input
212 18
output
12
input
5 45 12 27 30 18
output
15
Note
In the first example the optimal way is to do the assignment: x2 = x2 - x1.
In the second example the optimal sequence of operations is: x3 = x3 - x2, x2 = x2 - x1
意思很简单,给出n个数,执行如下操作若干次:从中任取两个数,满足,然后赋值,直到所有数的和最小。
根据题目,得出如下思路,将给出的n个数从小到大排序,为了让操作次数尽可能少,让第n个减去第n-1个,再将得
出的新数组排序,重复执行上述操作。可发现,当所有数都相等时,操作结束,此时的和最小。
题目很简单,但是演算的时候可以发现,这是在求n个数的最大公约数,所以特别将该题记录下来。代码如下:
相关文章推荐
- Codeforces Round #228 (Div. 2) A. Fox and Number Game
- Codeforces Round #304 (Div. 2) D. Soldier and Number Game 数论 筛表法
- Codeforces Round #228 Div1 B Fox and Minimal path
- Codeforces Round #304 (Div. 2) D Soldier and Number Game
- Codeforces Round #228 (Div. 1) B. Fox and Minimal path
- Codeforces Round #304 (Div. 2) D - Soldier and Number Game
- Codeforces Round #228 (Div. 1) A. Fox and Box Accumulation 贪心
- Codeforces Round #228 Fox and Card Game 解题报告
- Codeforces Round #228 (Div. 2) B. Fox and Cross
- Codeforces Round #228 (Div. 2) C. Fox and Box Accumulation
- Codeforces Round #228 (Div. 2)B. Fox and Cross
- Codeforces Round #228 (Div. 2) B Fox and Cross(DFS)
- Codeforces Round #290 (Div. 2) E Fox And Dinner
- CodeforcesRound#253(Div2) D Andrey and Problem
- Codeforces Round #290 (Div. 2) B. Fox And Two Dots
- C. Fox And Names(Codeforces Round #290 (Div. 2))
- Codeforces Round #280 (Div. 2) D. Vanya and Computer Game 数学+预处理
- Codeforces Round #174 (Div. 2) B. Cows and Poker Game(简单)
- Codeforces Round #290 (Div. 1)B. Fox And Jumping
- Codeforces Round #169 (Div. 2):E - Little Girl and Problem on Trees