URAL 1010 Discrete Function【简单暴力】

链接:



E - Discrete Function
Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

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


题意:

给出第一个数 N 表示有 N 个点
下面 N 行 每行一个数, 可以看成是纵坐标的值.比如说第一个数 a1, 代表坐标(1,a1)
要你找出两个点,要求两点之间的所有点【for which all points between them are below than straight line 这里比较坑,读题时一般会忽略,然后就蒙了】都在这两点连线的下面。然后输出这两点的横坐标就好了。(也就是第几个点)
注意:输出时保证第一个点的横坐标小于第二个点的横坐标。

算法:

暴力求解
先上一张群里看到的图片

思路:

就是找相邻的两点,输出差值最大的相邻两点的下标就好了Orz...一道没有什么意义的题.
PS:开始没有想清楚为什么一定是相邻的两点,直接忽略了 between them就以为是求所有点中斜率绝对值最大的那两个了。

证明:

KB大神给我上的图:

如果不是相邻的 两个点,那么所求的斜率必定不是最大的,比如说上图圆中的那条线
╮(╯▽╰)╭都是between them 惹的祸,这样一来,题目就水了.

注意:输入的数是超 int 的了。

code:

Accepted112 KB46 msVisual C++ 2010563 B
习惯用__int64了。。。改成 double 也可以过
#include<stdio.h>
int main()
{
    int n;
    __int64 a,b,c;
    int x1,x2;
    while(scanf("%d", &n) != EOF)
    {
        __int64 Max = 0, ans;
        x1 = 1; x2 = 2;
        scanf("%I64d", &a);
        for(int i = 2; i <= n; i++)
        {
            scanf("%I64d", &b);
            ans = b-a;
            ans = ans >= 0 ? ans : -ans;

            if(ans > Max)
            {
                Max = ans;
                x1 = i-1;
                x2 = i;
            }
            a = b; //存
        }
        printf("%d %d\n", x1,x2);
    }
    return 0;
}







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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值