A11087 | Weather Tomorrow
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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.
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.
输入格式
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.
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.
输出格式
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$ .
输入输出样例
输入 #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$ .
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$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted