CF340C.Tourist Problem
普及/提高-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Iahub is a big fan of tourists. He wants to become a tourist himself, so he planned a trip. There are n destinations on a straight road that Iahub wants to visit. Iahub starts the excursion from kilometer 0. The n destinations are described by a non-negative integers sequence _a_1, _a_2, ..., a__n. The number a__k represents that the _k_th destination is at distance a__k kilometers from the starting point. No two destinations are located in the same place.
Iahub wants to visit each destination only once. Note that, crossing through a destination is not considered visiting, unless Iahub explicitly wants to visit it at that point. Also, after Iahub visits his last destination, he doesn't come back to kilometer 0, as he stops his trip at the last destination.
The distance between destination located at kilometer x and next destination, located at kilometer y, is |x - y| kilometers. We call a "route" an order of visiting the destinations. Iahub can visit destinations in any order he wants, as long as he visits all n destinations and he doesn't visit a destination more than once.
Iahub starts writing out on a paper all possible routes and for each of them, he notes the total distance he would walk. He's interested in the average number of kilometers he would walk by choosing a route. As he got bored of writing out all the routes, he asks you to help him.
伊阿胡布非常喜爱游客,他也想成为一名游客,因此计划了一次旅行。在一条笔直的道路上共有 n 个目的地,伊阿胡布希望全部游览。他从 0 千米处出发。这 n 个目的地由一个非负整数序列 a1,a2,…,an 描述;其中 ak 表示第 k 个目的地距离起点 ak 千米。任意两个目的地均不位于同一位置。
伊阿胡布希望每个目的地仅访问一次。注意:经过某个目的地并不算作访问,除非伊阿胡布明确选择在该点访问它。此外,在访问完最后一个目的地后,他不会返回 0 千米处,而是直接在最后一个目的地结束整个行程。
位于 x 千米处的目的地与下一个位于 y 千米处的目的地之间的距离为 ∣x−y∣ 千米。我们将访问目的地的顺序称为一条“路线”。只要伊阿胡布访问全部 n 个目的地、且每个目的地至多访问一次,那么他可以按任意顺序访问这些目的地。
伊阿胡布开始在纸上列出所有可能的路线,并对每条路线计算他需要行走的总距离。他感兴趣的是:随机选择一条路线时,他平均需要行走多少千米? 由于他厌倦了手动列出所有路线,于是请你来帮助他。
输入格式
The first line contains integer n (2 ≤ n ≤ 105). Next line contains n distinct integers _a_1, _a_2, ..., a__n (1 ≤ a__i ≤ 107).
第一行包含一个整数 n(2≤n≤105)。下一行包含 n 个互不相同的整数 a1,a2,…,an(1≤ai≤107)。
输出格式
Output two integers — the numerator and denominator of a fraction which is equal to the wanted average number. The fraction must be irreducible.
输出两个整数——一个分数的分子和分母,该分数等于所要求的平均数。该分数必须为最简分数。
输入输出样例
输入#1
3 2 3 5
输出#1
22 3
说明/提示
Consider 6 possible routes:
- [2, 3, 5]: total distance traveled: |2 – 0| + |3 – 2| + |5 – 3| = 5;
- [2, 5, 3]: |2 – 0| + |5 – 2| + |3 – 5| = 7;
- [3, 2, 5]: |3 – 0| + |2 – 3| + |5 – 2| = 7;
- [3, 5, 2]: |3 – 0| + |5 – 3| + |2 – 5| = 8;
- [5, 2, 3]: |5 – 0| + |2 – 5| + |3 – 2| = 9;
- [5, 3, 2]: |5 – 0| + |3 – 5| + |2 – 3| = 8.
The average travel distance is
=
=
.
考虑 6 种可能的路线:
- [2, 3, 5]:总行驶距离为 |2 – 0| + |3 – 2| + |5 – 3| = 5;
- [2, 5, 3]:|2 – 0| + |5 – 2| + |3 – 5| = 7;
- [3, 2, 5]:|3 – 0| + |2 – 3| + |5 – 2| = 7;
- [3, 5, 2]:|3 – 0| + |5 – 3| + |2 – 5| = 8;
- [5, 2, 3]:|5 – 0| + |2 – 5| + |3 – 2| = 9;
- [5, 3, 2]:|5 – 0| + |3 – 5| + |2 – 3| = 8。
平均行驶距离为
=
=
。
输入解题思路,AI测评打分。不知道怎么写?