Discrete Function(timus1010,暴力)

本文探讨如何在离散函数中找到两个点,使得所有位于这两点之间的点都位于连接这两点的直线下方,并且该直线的斜率最大。通过计算相邻点的斜率并寻找最大的绝对值斜率来确定所需点。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值