zoukankan      html  css  js  c++  java
  • 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
    
    #include <iostream>
    #include <algorithm>
    #include <cstdio>
    #include <vector>
    
    using namespace std;
    
    int main(){
        int n;
        cin >> n;
        vector<long long > point(n+1,0);
        for(int i = 1; i <= n; i ++  ) cin >>point[i];
        long long  maxIncli = 0;
        int idx =1;
        for(int i = 2; i <=n; i ++ ){
            if(maxIncli < abs(point[i]-point[i-1])){
                idx = i;
                maxIncli = abs(point[i]-point[i-1]);
            }
        }
        cout<< idx-1<<" "<<idx <<endl;
        return 0;
    }
    
  • 相关阅读:
    设计模式之简单工厂模式
    设计模式之工厂方法模式
    设计模式之抽象工厂模式
    面向对象设计原则
    Spring与Struts整合
    Spring与Hibernate、Mybatis整合
    Java中执行外部命令
    Spring3之Security
    综合练习:词频统计
    组合数据类型综合练习
  • 原文地址:https://www.cnblogs.com/xiongqiangcs/p/3035195.html
Copyright © 2011-2022 走看看