http://acm.timus.ru/problem.aspx?space=1&num=1010
1010. Discrete Function
Time limit: 1.0 second
Memory limit: 64 MB
There is a discrete function. It is specified for integer arguments from 1 to N (2 ≤ N ≤ 100000). Each value of the function is longint (signed long in C++). You have to find such two points of the function for which all points between them are below than straight line connecting them and inclination of this straight line is the largest.
Input
There is an N in the first line. Than N lines follow with the values of the function for the arguments 1, 2, …, N respectively.
Output
A pair of integers, which are abscissas of the desired points, should be written into one line of output. The first number must be less then the second one. If it is any ambiguity your program should write the pair with the smallest first number.
Sample
input output
3
2
6
4
1 2
Problem Source: Third Open USTU Collegiate Programming Contest (PhysTech Cup), March 18, 2000
Tags: none (hide tags for unsolved problems)
Difficulty: 245 Printable version Submit solution Discussion (62)
All submissions (21340) All accepted submissions (5687) Solutions rating (4180)
解析:只计算相邻的斜率即可;
注意绝对值
*/
#include<stdio.h> #include<string.h> #include<math.h> #include <iostream> using namespace std; const int maxn=1000000+10; double y[maxn]; int main() { int n; int i,j; double max,k; while(scanf("%d",&n)!=EOF) { for(i=1;i<=n;i++) cin>>y[i]; int x1; max=-1; for(i=2;i<=n;i++) { k=y[i]-y[i-1]; if(max<fabs(k)) {x1=i-1; max=fabs(k); } } printf("%d %d\n",x1,x1+1); } return 0; }