Description
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, shocould be written into one line of output. the first number must be less then the second one. if it is any ambiguity your program shocould write the pair with the smallest first number.
Sample Input
Input output
3
2
6
4
1 2
This question has only been understood for a long time. Let's explain this. Set the discrete function to f (n). The input data is f (1) = 2;
F (2) = 6; f (3) = 4. now there are three vertices, right? Now we need to find two vertices from these three vertices so that the points between them cannot be above the straight line, and the inclination angle (Note: not the slope, but the inclination angle) must be the largest. Obviously, if it is a little in a straight line, the inclination of this line is definitely not the biggest, so the answer to the question must be two adjacent points, the question is converted to the absolute value of the distance between neighboring points.
[Cpp]
# Include <iostream>
# Include <stdio. h>
# Include <stdlib. h>
# Include <math. h>
Using namespace std;
Int main ()
{
Long int a [100001];
Int n, t, I;
Scanf ("% d", & n );
For (I = 1; I <= n; I ++)
{
Scanf ("% lld", & a [I]);
}
Long max =-1;
For (I = 2; I <= n; I ++)
{
If (llabs (a [I]-a [I-1])> max)
{
Max = llabs (a [I]-a [I-1]);
T = I;
}
}
Printf ("% d \ n", T-1, t );
Return 0;
}
Author: CSUST_ACM