Love丶FFC's Blog

PAT乙级:1010 一元多项式求导

2020-02-01 21:51:57
阅读:620   •   评论:10
标签:,

设计函数求一元多项式的导数。(注:x​n​​(n为整数)的一阶导数为nx​n−1​​。)

输入格式:

以指数递降方式输入多项式非零项系数和指数(绝对值均为不超过 1000 的整数)。数字间以空格分隔。

输出格式:

以与输入相同的格式输出导数多项式非零项的系数和指数。数字间以空格分隔,但结尾不能有多余空格。注意“零多项式”的指数和系数都是 0,但是表示为 0 0

输入样例:

3 4 -5 2 6 1 -2 0

输出样例:

12 3 -10 1 6 0

编程语言:Python

解题思想:

1.因为题目的输入是递减的多项式,所以一旦发现某个多项式指数小于等于0就要结束求导,只输出之前的结果

2.创建两个列表存放系数、指数,再创建一个列表存放求导后的多项式结果

3.对具体的情况进行判断

时间复杂度:O(N)

代码如下:

  1. Number = list(map(int, input().split()))
  2.  
  3. Coefficient, Index = list(), list() # 存放多项式的系数、指数
  4. Derivative = list()
  5.  
  6. for i in range(len(Number)):
  7. if i % 2 == 0:
  8. Coefficient.append(Number[i]) # 存放系数
  9. else:
  10. Index.append(Number[i]) # 存放指数
  11.  
  12. for i in range(len(Coefficient)):
  13. if Coefficient[i] != 0 and Index[i] != 0:
  14. Coefficient[i] *= Index[i]
  15. Index[i] -= 1
  16. Derivative.append([Coefficient[i], Index[i]]) # 存放求导后的多项式
  17. elif Coefficient[i] == 0:
  18. Coefficient[i], Index[i] = 0, 0
  19. Derivative.append([Coefficient[i], Index[i]]) # 存放求导后的多项式
  20.  
  21. if len(Derivative) == 0: # 首项的指数就小于等于0,导致后续多项式不再求导,这种情况需要输出0 0
  22. print(0, 0)
  23. else:
  24. for i in range(len(Derivative)):
  25. if i != len(Derivative) - 1:
  26. print(Derivative[i][0], Derivative[i][1], end=' ')
  27. else:
  28. print(Derivative[i][0], Derivative[i][1])

评论板

共有 10 条评论

  1. fruinly

    does propecia really work Nausea and vomiting due to chemotherapy 2 grams of taurine daily for 6 months has been used

  2. cheap jordan shoes

    I just wanted to thank you for the fast service. or possibly a they look great. I received them a day earlier than expected. the same as I will definitely continue to buy from this site. situation I will recommend this site to my friends. Thanks!
    cheap jordan shoes https://www.realcheapretrojordanshoes.com/

  3. jordans for cheap

    I just wanted to thank you for the fast service. perhaps they look great. I received them a day earlier than expected. including the I will definitely continue to buy from this site. in any event I will recommend this site to my friends. Thanks!
    jordans for cheap https://www.realjordansretro.com/

  4. cheap louis vuitton handbags

    I just wanted to thank you for the fast service. or maybe they look great. I received them a day earlier than expected. themselves I will definitely continue to buy from this site. in any event I will recommend this site to my friends. Thanks!
    cheap louis vuitton handbags https://www.louisvuittonsoutletstore.com/

  5. FoorryNox

    So what is responsible for keeping muscle on the body propecia on sale Body mass index BMI was calculated as weight kg divided by the square of height m 2

  6. cheap jordans online

    Read reviews and was a little hesitant since I had already inputted my order. or but thank god, I had no issues. including received item in a timely matter, they are in new condition. an invaluable so happy I made the purchase. Will be definitely be purchasing again.
    cheap jordans online https://www.cheapjordanssneakers.com/

  7. jordans for cheap

    Read reviews and was a little hesitant since I had already inputted my order. properly but thank god, I had no issues. the same as received item in a timely matter, they are in new condition. in any event so happy I made the purchase. Will be definitely be purchasing again.
    jordans for cheap https://www.cheapauthenticjordans.com/

  8. authentic louis vuitton outlet

    Read reviews and was a little hesitant since I had already inputted my order. on the other hand but thank god, I had no issues. for instance received item in a timely matter, they are in new condition. manner in which so happy I made the purchase. Will be definitely be purchasing again.
    authentic louis vuitton outlet https://www.louisvuittonsoutletonline.com/

  9. cheap real jordans

    Read reviews and was a little hesitant since I had already inputted my order. or maybe but thank god, I had no issues. for instance received item in a timely matter, they are in new condition. situation so happy I made the purchase. Will be definitely be purchasing again.
    cheap real jordans https://www.realjordansshoes.com/

  10. Preliaf

    Inhibition of HIF 1 and wild type p53 stimulated transcription by codon Arg175 p53 mutants with selective loss of functions cialis 20mg price

--------查看该分类下最新文章--------
^
新版博客正在完善中!域名: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 -

已运行:

访问量:502414