Discrete Function(简单数学题)

Discrete Function

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.

Example

inputoutput
3
2
6
4
1 2

//简单数学题,题意是,在一个横坐标是 1 - N 的整数的坐标里,每个整数代表纵坐,若任意两个点都可连成一条直线,问倾角最大的两个点横坐标是?

//容易想到,必须是两个相邻的点才有可能倾角最大,所以一重循环就解决了

 1 #include<stdio.h>
 2 #include<math.h>
 3 double a[100005];
 4 int main()
 5 {
 6  int n;
 7 
 8  scanf("%d",&n);
 9  for(int i=1;i<=n;i++) scanf("%lf",&a[i]);
10 
11  int s=1,e=2;
12  double ans=-1;
13  for(int i=2;i<=n;i++)
14  {
15   double tmp=fabs(a[i]-a[i-1]);
16   if(ans<tmp)
17   {
18    s=i-1;
19    e=i;
20    ans=tmp;
21   }
22  }
23  printf("%d %d
",s,e);
24  return 0;
25 }
View Code
原文地址:https://www.cnblogs.com/haoabcd2010/p/6171416.html