Codeforces847M Weather Tomorrow
来源:互联网 发布:紫薇斗数排盘软件 编辑:程序博客网 时间:2024/06/03 08:33
标签:模拟,计算几何
Vasya cameup with his own weather forecasting method. He knows the information about theaverage air temperature for each of the last n days. Assume that the average air temperaturefor each day is integral.
Vasyabelieves that if the average temperatures over the last n days form an arithmetic progression, wherethe first term equals to the average temperature on the first day, the secondterm equals to the average temperature on the second day and so on, then theaverage temperature of the next (n + 1)-th daywill 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 ofthe n-th day.
Your taskis to help Vasya predict the average temperature for tomorrow, i. e. for the (n + 1)-th day.
Input
The firstline contains a single integer n (2 ≤ n ≤ 100) — the number ofdays for which the average air temperature is known.
The secondline contains a sequence of integers t1, t2, ..., tn ( - 1000 ≤ ti ≤ 1000) —where ti is theaverage temperature in the i-th day.
Output
Print theaverage air temperature in the (n + 1)-th day,which Vasya predicts according to his method. Note that the absolute value ofthe predicted temperature can exceed 1000.
Example
Input
5
10 5 0 -5 -10
Output
-15
Input
4
1 1 1 1
Output
1
Input
3
5 1 -5
Output
-5
Input
2
900 1000
Output
1100
Note
In thefirst example the sequence of the average temperatures is an arithmeticprogression where the first term is 10 and eachfollowing terms decreases by 5. So thepredicted average temperature for the sixth day is - 10 - 5 = - 15.
In thesecond example the sequence of the average temperatures is an arithmeticprogression where the first term is 1 and eachfollowing terms equals to the previous one. So the predicted averagetemperature in the fifth day is 1.
In thethird example the average temperatures do not form an arithmetic progression,so the average temperature of the fourth day equals to the temperature of thethird day and equals to - 5.
In thefourth example the sequence of the average temperatures is an arithmeticprogression where the first term is 900 and eachthe following terms increase by100. Sopredicted average temperature in the third day is 1000 + 100 = 1100.
计算几何的入门题,初二数学的难度,判断这些点是否在同一条直线上
Code
#include<bits/stdc++.h>#define rep(i,a,b) for(int i=a;i<=b;i++)#define dep(i,a,b) for(int i=a;i>=b;i--)using namespace std; int n,d,flag,a[305]; int main(){ cin>>n; rep(i,1,n)scanf("%d",&a[i]); d=a[2]-a[1]; rep(i,2,n-1) if(a[i+1]-a[i]!=d)flag=1; if(flag==0)cout<<a[n]+d; else cout<<a[n]; return 0;}
- Codeforces847M Weather Tomorrow
- codeforces 847M Weather Tomorrow
- Tomorrow
- tomorrow
- weather
- weather
- Weather
- Tomorrow journey
- From tomorrow
- tomorrow presentation
- tomorrow-theme
- weather glossary
- Weather Report
- googole weather
- weather jp
- Weather Forecast
- xml weather
- weather.xml
- Codeforces847K Travel Cards
- PHP实现限制域名从而保护源代码不被拷贝
- Number of Islands
- Python入门系列9:set 集合
- maven配置
- Codeforces847M Weather Tomorrow
- Calandar、Date、String之间的相互转化
- 作业
- 2017-2018 ACM-ICPC, NEERC解题报告
- 关于各大协议
- 作业1
- 乐视网CEO梁军:现在就是缺钱 正在重新学习做生意 2017年09月20日01:18 新京报 37 微博 微信 QQ空间 添加喜爱 乐视网CEO梁军。 新京报记者 吴江 摄乐视网CEO梁军。 新京
- python继承
- 作业