Love丶FFC's Blog

CCF-CSP_20190902:小明种苹果(续)

2019-12-09 08:30:19
阅读:1184   •   评论:11
标签:,

编程语言:Python

解题思想:

1.T,E统计在输入的时候就进行

2.注意E统计的是发生掉落的苹果棵数,而不是发生掉落的次数

3.使用T来判断E的情况

4.因为使用列表,需要对E额外进行两次首尾相连的特殊情况判断。

时间复杂度:O(n^2)

IDE代码如下:

  1. NOT = int(input()) # 输入苹果树的棵数
  2. Operate = list() # 存放每一行输入值的列表
  3. Continuous = [0 for i in range(NOT)] # 存放掉落苹果情况的苹果树编号
  4. T, D, E = 0, 0, 0 # 分别代表疏果操作结束后总的苹果个数,掉落苹果的苹果棵数,连续三棵树发生掉落苹果的情况的组数
  5.  
  6. # 完成T和D的统计
  7. for i in range(NOT):
  8. Operate = list(map(int, input().split())) # 将输入的一行全部存入列表中
  9. Initial = Operate[1] # 每棵苹果树记录的初始苹果个数为列表下标的第1个元素
  10. DJudge = False # 该苹果树是否掉落
  11. for j in range(Operate.__len__() - 2): # 对列表的最后(列表-2)个元素进行遍历
  12. if Operate[j + 2] > 0: # 发现更新的苹果个数
  13. if Operate[j + 2] < Initial and DJudge == False: # 该苹果树首次发生苹果掉落的情况
  14. D += 1
  15. DJudge = True
  16. Continuous[i] = 1 # 将该苹果树的掉落标记改为1
  17. Initial = Operate[j + 2] # 更新记录的苹果个数
  18. else: # 疏果个数
  19. Initial += Operate[j + 2]
  20. T += Initial
  21.  
  22. # 完成E的统计
  23. if T < 3: # 不可能存在连续3棵掉落的情况
  24. E = 0
  25. else:
  26. for i in range(Continuous.__len__() - 2): # 对掉落苹果树列表进行遍历
  27. if Continuous[i] == Continuous[i + 1] == Continuous[i + 2] == 1:
  28. E += 1
  29. if Continuous[Continuous.__len__() - 2] == Continuous[Continuous.__len__() - 1] == Continuous[0] == 1: # 对特殊情况进行判断
  30. E += 1
  31. if Continuous[Continuous.__len__() - 1] == Continuous[0] == Continuous[1] == 1: # 对特殊情况进行判断
  32. E += 1
  33. print(T, D, E)

评论板

共有 11 条评论

  1. cheap jordan shoes

    Read reviews and was a little hesitant since I had already inputted my order. or possibly but thank god, I had no issues. since the 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 jordan shoes https://www.retrocheapjordansshoes.com/

  2. cheap jordans

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

  3. cheap jordans online

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

  4. authentic louis vuitton outlet

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

  5. Knitant

    You know it s bad news for gout viagra coupon cvs parlodel gentle laxative bisacodyl 5 mg dosage Internal company emails presented at the trial on Monday showed BP saying publicly after the spill in April 2010 that 5, 000 barrels of oil a day were leaking into the ocean when it knew up to 100, 000 barrels a day could have been leaking

  6. invoimi

    Augustine BHpJlBaviRoci 6 29 2022 buying cialis online reviews Epub 2015 Oct 17

  7. Knwmvy

    fenofibrate 200mg uk order tricor 160mg for sale order fenofibrate 160mg sale

  8. Tinysk

    cialis 20mg oral sildenafil 50mg tablets sildenafil order

  9. Aknsym

    order ketotifen generic order tofranil 25mg without prescription order tofranil 25mg generic

  10. Rgrpeq

    order minoxytop online order minoxytop solution top rated ed pills

  11. Ekcmps

    buy acarbose 50mg for sale purchase fulvicin without prescription griseofulvin drug

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

已运行:

访问量:493087