CF847M.Weather Tomorrow

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Vasya came up with his own weather forecasting method. He knows the information about the average air temperature for each of the last n days. Assume that the average air temperature for each day is integral.

Vasya believes that if the average temperatures over the last n days form an arithmetic progression, where the first term equals to the average temperature on the first day, the second term equals to the average temperature on the second day and so on, then the average temperature of the next (n + 1)-th day will be equal to the next term of the arithmetic progression. Otherwise, according to Vasya's method, the temperature of the (n + 1)-th day will be equal to the temperature of the n-th day.

Your task is to help Vasya predict the average temperature for tomorrow, i. e. for the (n + 1)-th day.

瓦西娅提出了他自己的天气预报方法。他掌握了过去 nn 天每天的平均气温数据。假设每天的平均气温均为整数。

瓦西娅认为:如果过去 nn 天的平均气温构成一个等差数列(其中首项为第一天的平均气温,第二项为第二天的平均气温,依此类推),那么第 (n+1)(n+1) 天的平均气温将等于该等差数列的下一项;否则,按照瓦西娅的方法,第 (n+1)(n+1) 天的气温将等于第 nn 天的气温。

你的任务是帮助瓦西娅预测明天(即第 (n+1)(n+1) 天)的平均气温。

输入格式

The first line contains a single integer n (2 ≤ n ≤ 100) — the number of days for which the average air temperature is known.

The second line contains a sequence of integers _t_1, _t_2, ..., t__n ( - 1000 ≤ t__i ≤ 1000) — where t__i is the average temperature in the i-th day.

第一行包含一个整数 nn(2≤n≤1002 \leq n \leq 100)—— 表示已知平均气温的天数。

第二行包含一个整数序列 t1, t2, ..., tnt_1,\,t_2,\,...,\,t_n(−1000≤ti≤1000-1000 \leq t_i \leq 1000),其中 tit_i 表示第 ii 天的平均气温。

输出格式

Print the average air temperature in the (n + 1)-th day, which Vasya predicts according to his method. Note that the absolute value of the predicted temperature can exceed 1000.

输出瓦西亚根据其方法预测的第 n+1n+1 天的平均气温。注意,预测温度的绝对值可能超过 1000。

输入输出样例

  • 输入#1

    5
    10 5 0 -5 -10

    输出#1

    -15
  • 输入#2

    4
    1 1 1 1

    输出#2

    1
  • 输入#3

    3
    5 1 -5

    输出#3

    -5
  • 输入#4

    2
    900 1000

    输出#4

    1100

说明/提示

In the first example the sequence of the average temperatures is an arithmetic progression where the first term is 10 and each following terms decreases by 5. So the predicted average temperature for the sixth day is  - 10 - 5 =  - 15.

In the second example the sequence of the average temperatures is an arithmetic progression where the first term is 1 and each following terms equals to the previous one. So the predicted average temperature in the fifth day is 1.

In the third example the average temperatures do not form an arithmetic progression, so the average temperature of the fourth day equals to the temperature of the third day and equals to  - 5.

In the fourth example the sequence of the average temperatures is an arithmetic progression where the first term is 900 and each the following terms increase by 100. So predicted average temperature in the third day is 1000 + 100 = 1100.

在第一个例子中,平均气温序列是一个等差数列,首项为 1010,之后每一项均比前一项减少 55。因此,第六天的预测平均气温为 −10−5=−15-10 - 5 = -15。

在第二个例子中,平均气温序列是一个等差数列,首项为 11,之后每一项均等于前一项。因此,第五天的预测平均气温为 11。

在第三个例子中,平均气温不构成等差数列,因此第四天的平均气温等于第三天的气温,即 −5-5。

在第四个例子中,平均气温序列是一个等差数列,首项为 900900,之后每一项均比前一项增加 100100。因此,第三天的预测平均气温为 1000+100=11001000 + 100 = 1100。

输入解题思路,AI测评打分。不知道怎么写?

首页