Love丶FFC's Blog

CCF-CSP_20160901:最大波动

2019-09-18 22:06:37
阅读:1217   •   评论:7
标签:,

问题描述

小明正在利用股票的波动程度来研究股票。小明拿到了一只股票每天收盘时的价格,他想知道,这只股票连续几天的最大波动值是多少,即在这几天中某天收盘价格与前一天收盘价格之差的绝对值最大是多少。

输入格式

输入的第一行包含了一个整数n,表示小明拿到的收盘价格的连续天数。第二行包含n个正整数,依次表示每天的收盘价格。

输出格式

输出一个整数,表示这只股票这n天中的最大波动值。

样例输入

6
2 5 5 7 3 5

样例输出

4

样例说明

第四天和第五天之间的波动最大,波动值为|3-7|=4。

评测用例规模与约定

对于所有评测用例,2 ≤ n ≤ 1000。股票每一天的价格为1到10000之间的整数。

编程语言:Java

解题思想:

1.枚举法

时间复杂度:O(n)

IDE代码如下:

  1. package CCF_CSP;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class _20160901_100point {
  6.  
  7. public static void main(String[] args) {
  8. Scanner scanner = new Scanner(System.in);
  9. int n = scanner.nextInt(); //拿到的收盘价格的天数
  10. int[] price = new int[n]; //每天的收盘价格
  11.  
  12. for(int i=0;i<n;i++)
  13. {
  14. price[i] = scanner.nextInt();
  15. }
  16.  
  17. int maxdistance = Math.abs(price[1]-price[0]); //定义初始最大差距
  18.  
  19. for(int i=2;i<n;i++)
  20. {
  21. if(Math.abs(price[i]-price[i-1]) > maxdistance) //存在更大差距
  22. {
  23. maxdistance = Math.abs(price[i]-price[i-1]);
  24. }
  25. }
  26.  
  27. System.out.println(maxdistance);
  28. }
  29.  
  30. }
  31.  

评论板

共有 7 条评论

  1. FoorryNox

    Monitor Closely 1 propofol and quazepam both increase sedation cialis 20 mg afatinib will increase the level or effect of dabigatran by P glycoprotein MDR1 efflux transporter

  2. Preliaf

    Experimental Biology, 2001, 39, 12, 1235 42 comprar levitra espana 24 This large 2 by 2 factorial study randomly assigned 5, 177 patients undergoing nonemergency angiography to receive isotonic sodium bicarbonate vs isotonic saline as well as oral acetylcysteine vs placebo

  3. PAhxgSog

    i took a viagra and it didn’t work If you canГў t figure out how to set up a filter on your email program, just put the question into Google that will find the answer for you

  4. Uxdcll

    buy tricor 200mg generic tricor pill tricor 160mg generic

  5. Idnjtf

    buy cialis pill viagra cost viagra 50mg ca

  6. Aaxfam

    acarbose pills micronase order buy fulvicin 250 mg without prescription

  7. Pipmya

    minoxytop medication tamsulosin where to buy can you buy ed pills online

--------查看该分类下最新文章--------
^
新版博客正在完善中!域名:http://www.loveffc:8080,点击跳转,完全移植后将去除端口号。

Copyright © 2018 - 2021 FFC的小站 - 滇 ICP 备 18010780 号 - 1

- Powered by WordPress & AliYun · Theme by FFC -

- Environment by Windows & XAMPP · Designed by WebStorm & VSCode -

已运行:

访问量:502720