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, 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
input output
3
2
6
4
1 2
這個題看了老半天才懂。這麼解釋吧,設離散函數為f(n),根據輸入數據則是,f(1) = 2;
f(2) = 6; f(3) = 4.現在有三個點 了對吧,現在就是要從這三個點中找出兩個點,使在這兩個點之間的點不能再這條直線的上方,並且傾角(注意:不是斜率,是傾角)要最大。顯然,如果有點在一條直線下的話那麼這條直線傾角絕對不是最大的,所以滿足題意的答案必然是兩個相鄰的點,題目就轉化為了求相鄰點距離的絕對值了。
[cpp]
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
using namespace std;
int main()
{
long long int a[100001];
int n,t,i;
scanf("%d",&n);
for(i=1;i<=n;i++)
{
scanf("%lld",&a[i]);
}
long 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 %d\n",t-1,t);
return 0;
}