21535_GeometricSequence

2022-5-16 18:19| 发布者: Hocassian| 查看: 38| 评论: 0|原作者: 肇庆学院ACM合集

摘要:
C:\Users\Administrator\Downloads\2019-10-12-10-14-4-89505400797100-Problem List-采集的数据-后羿采集器.html

Pro.ID

21535

Title

Geometric Sequence

Title链接

http://10.20.2.8/oj/exercise/problem?problem_id=21535

AC

0

Submit

0

Ratio

-

时间&空间限制

  • Time Limit: 1000/500 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others)
  • 描述

    A sequence of integers is called a geometric sequence if the ratio of consecutive numbers is constant.

    For example, (3, 6, 12, 24) is a geometric sequence (each term is equal to twice the previous number).

    Now, with such a sequence, we will shuffle it and remove some of the elements.

    Given the result of such a transformation, try to recover the "geometric ratio" of the original sequence, i.e. the ratio of consecutive numbers.

    If there are multiple possible ratios, output the one with the greatest absolute value. If there is still a tie, output the positive one.

    If there is no such sequence, output 0.

    输入

    The first line of input contains a single integer, 2 ≤ N ≤ 100,000, the number of integers in the transformed sequence.

    Following this will be N lines, each containing a single integer of the transformed sequence (each element will be less than or equal to 1018 in absolute value, and no element will be zero).

    输出

    Description

    A sequence of integers is called a geometric sequence if the ratio of consecutive numbers is constant.

    For example, (3, 6, 12, 24) is a geometric sequence (each term is equal to twice the previous number).

    Now, with such a sequence, we will shuffle it and remove some of the elements.

    Given the result of such a transformation, try to recover the "geometric ratio" of the original sequence, i.e. the ratio of consecutive numbers.

    If there are multiple possible ratios, output the one with the greatest absolute value. If there is still a tie, output the positive one.

    If there is no such sequence, output 0.

    Input

    The first line of input contains a single integer, 2 ≤ N ≤ 100,000, the number of integers in the transformed sequence.

    Following this will be N lines, each containing a single integer of the transformed sequence (each element will be less than or equal to 1018 in absolute value, and no element will be zero).

    Output

    The ratio of the original sequence (if one exists). The relative error of the answer must be within 10-9. That is, (abs(answer - expected) / expected < 10-9).

    Sample Input

    3
    1
    3
    27

    Sample Output

    3

    Hint

    The original sequence could have been (1, 3, 9, 27, ...) or (..., 27, 9, 3, 1); the former has the greater ratio (3).

    Source

    样例输入

    3
    1
    3
    27

    样例输出

    3

    提示

    The original sequence could have been (1, 3, 9, 27, ...) or (..., 27, 9, 3, 1); the former has the greater ratio (3).


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部