URAL 1010 Discrete Function(解题报告)


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

这个题看了老半天才懂。这么解释吧,设离散函数为fn),根据输入数据则是,f(1) = 2;

f(2) = 6; f(3) = 4.现在有三个点 了对吧,现在就是要从这三个点中找出两个点,使在这两个点之间的点不能再这条直线的上方,并且倾角(注意:不是斜率,是倾角)要最大。显然,如果有点在一条直线下的话那么这条直线倾角绝对不是最大的,所以满足题意的答案必然是两个相邻的点,题目就转化为了求相邻点距离的绝对值了。 

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




  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值