Ural 1010. Discrete Function

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

inputoutput
3
2
6
4
1 2
Problem Source: Third Open USTU Collegiate Programming Contest (PhysTech Cup), March 18, 2000

 
 
    ​存在一个离散函数,已知定义域为 1 到 N 的整数点,对应函数值在输入中。在图像上找到两个点,使得在它们之间的点都在两点连成直线的下方,且直线的倾斜角最大。
    实际上,如果这样的直线下方还有点的话,则必存在下方的点与原直线右端点连成的新直线斜率更大。所以,遍历相邻的两个点差值即可,可以直接在读取输入时就求出。
    可能我没懂题意,不明白为什么设 long 会WA,设double或long long才A。
 
#include <stdio.h>
#include <math.h>

double a[100002];

int main()
{
  long n, i, j;
  
double k=0;
  
scanf("%ld", &n);
  for (i = 0; i < n; i++)
    scanf("%lf", &a[i]);
  for (i = 1; i < n; i++) {
    if (k < fabs(a[i] - a[i-1])) {
      k = fabs(a[i]- a[i-1]);
      j = i;
    }
  }
  printf("%ld %ld\n", j, j+1);
  return 0; }
 





posted @ 2015-02-02 13:45  BlackStorm  阅读(319)  评论(0编辑  收藏  举报