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
    
    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 ", j, j+1);
      return 0; }
     





  • 相关阅读:
    HDU 4396
    Vijos1603 迷宫
    BZOJ1087 [SCOI2005] 互不侵犯King
    BZOJ2208 [JSOI2010] 连通数
    BZOJ1051 [HAOI2006] 受欢迎的牛
    BZOJ2751 [HAOI2012] 容易题(easy)
    BZOJ1015 [JSOI2008] 星球大战starwar
    BZOJ1012 [JSOI2008] 最大数maxnumber
    BZOJ1050 [HAOI2006] 旅行comf
    BZOJ2761 [JLOI2011] 不重复数字
  • 原文地址:https://www.cnblogs.com/BlackStorm/p/4267594.html
Copyright © 2011-2022 走看看