Love丶FFC's Blog

PAT乙级:1080 MOOC期终成绩

2020-04-12 02:00:59
阅读:929   •   评论:14
标签:,

对于在中国大学MOOC(http://www.icourse163.org/ )学习“数据结构”课程的学生,想要获得一张合格证书,必须首先获得不少于200分的在线编程作业分,然后总评获得不少于60分(满分100)。总评成绩的计算公式为 G=(G​mid−term​​×40%+G​final​​×60%),如果 G​mid−term​​>G​final​​;否则总评 G 就是 G​final​​。这里 G​mid−term​​ 和 G​final​​ 分别为学生的期中和期末成绩。

现在的问题是,每次考试都产生一张独立的成绩单。本题就请你编写程序,把不同的成绩单合为一张。

输入格式:

输入在第一行给出3个整数,分别是 P(做了在线编程作业的学生数)、M(参加了期中考试的学生数)、N(参加了期末考试的学生数)。每个数都不超过10000。

接下来有三块输入。第一块包含 P 个在线编程成绩 G​p​​;第二块包含 M 个期中考试成绩 G​mid−term​​;第三块包含 N 个期末考试成绩 G​final​​。每个成绩占一行,格式为:学生学号 分数。其中学生学号为不超过20个字符的英文字母和数字;分数是非负整数(编程总分最高为900分,期中和期末的最高分为100分)。

输出格式:

打印出获得合格证书的学生名单。每个学生占一行,格式为:

学生学号 Gp​​ Gmidterm​​ Gfinal​​ G

如果有的成绩不存在(例如某人没参加期中考试),则在相应的位置输出“−1”。输出顺序为按照总评分数(四舍五入精确到整数)递减。若有并列,则按学号递增。题目保证学号没有重复,且至少存在1个合格的学生。

输入样例:

6 6 7
01234 880
a1903 199
ydjh2 200
wehu8 300
dx86w 220
missing 400
ydhfu77 99
wehu8 55
ydjh2 98
dx86w 88
a1903 86
01234 39
ydhfu77 88
a1903 66
01234 58
wehu8 84
ydjh2 82
missing 99
dx86w 81

输出样例:

missing 400 -1 99 99
ydjh2 200 98 82 88
dx86w 220 88 81 84
wehu8 300 55 84 84

编程语言:Python

解题思想:

1.最重要的就是尽量降低时间复杂度

2.查找使用二分查找,排序使用Python自带的库函数结合lambda函数

3.先根据学号进行升序,最后根据总评进行升序

对于PAT乙级:1026 程序运行时题目中的四舍五入算法进行简化,可简化为 Number = int(Number + 0.5) 的形式,如Number=83.5,则运算后为84,如Number为83.2,则运算后为83。不需要再进行判断。

二分查找

时间复杂度:O(NlogN)

代码如下:

  1. def BinarySearch(target, left, right): # 二分查找
  2. if left <= right:
  3. mid = (left + right) // 2
  4. if target < QualifiedID[mid]:
  5. right = mid - 1
  6. return BinarySearch(target, left, right)
  7. if target > QualifiedID[mid]:
  8. left = mid + 1
  9. return BinarySearch(target, left, right)
  10. if target == QualifiedID[mid]:
  11. return mid
  12. else:
  13. return -1
  14.  
  15.  
  16. P, M, N = map(int, input().split()) # 参加(编程、期中考试、期末考试)的人数
  17. QualifiedID = list() # 创建一个列表专门存放学生的学号,方便比对
  18. QualifiedStudent = list() # 存放学生的学号和所有成绩
  19.  
  20. for i in range(P): # 输入P中的学号、分数
  21. Information = input().split()
  22. if int(Information[1]) >= 200:
  23. QualifiedID.append(Information[0])
  24. QualifiedStudent.append([Information[0], int(Information[1]), -1, -1, 0])
  25. QualifiedID.sort(reverse=False) # 按学号升序
  26. QualifiedStudent.sort(key=lambda x: x[0], reverse=False) # 按学号升序
  27.  
  28. for i in range(M): # 输入M中的学号、分数
  29. Information = input().split()
  30. Index = BinarySearch(Information[0], 0, len(QualifiedID) - 1) # 查找该学号之前是否参加过编程考试
  31. if Index != -1: # 参加过编程考试
  32. QualifiedStudent[Index][2] = int(Information[1]) # 更新该学号的期中成绩
  33.  
  34. for i in range(N): # 输入N中的学号、分数
  35. Information = input().split()
  36. Index = BinarySearch(Information[0], 0, len(QualifiedID) - 1)
  37. if Index != -1:
  38. QualifiedStudent[Index][3] = int(Information[1]) # 更新该学号的期末成绩
  39. if QualifiedStudent[Index][2] > QualifiedStudent[Index][3]: # 总评的第一种计算方式,同时四舍五入
  40. QualifiedStudent[Index][4] = int(QualifiedStudent[Index][2] * 0.4 + QualifiedStudent[Index][3] * 0.6 + 0.5)
  41. else: # 总评的第二种计算方式
  42. QualifiedStudent[Index][4] = QualifiedStudent[Index][3]
  43.  
  44. QualifiedStudent.sort(key=lambda x: x[4], reverse=True) # 按总评成绩降序
  45.  
  46. for i in range(len(QualifiedStudent)):
  47. if QualifiedStudent[i][4] >= 60: # 只输出总评不少于60分的信息
  48. print(QualifiedStudent[i][0], QualifiedStudent[i][1], QualifiedStudent[i][2], QualifiedStudent[i][3],
  49. QualifiedStudent[i][4])

评论板

共有 14 条评论

  1. Abupguele

    canadian pharmacy cialis I think the most valuable thing I learned was what I do not know

  2. Outlils

    In most cases, the only evidence they have to evaluate is the word of the person who survives tadalafil cialis from india

  3. cheap real jordans

    I just wanted to thank you for the fast service. or a they look great. I received them a day earlier than expected. which includes I will definitely continue to buy from this site. either way I will recommend this site to my friends. Thanks!
    cheap real jordans https://www.realcheapretrojordanshoes.com/

  4. cheap retro jordans

    I just wanted to thank you for the fast service. or just they look great. I received them a day earlier than expected. simillar to the I will definitely continue to buy from this site. either way I will recommend this site to my friends. Thanks!
    cheap retro jordans https://www.cheaprealjordan.com/

  5. cheap louis vuitton outlet

    I just wanted to thank you for the fast service. or else they look great. I received them a day earlier than expected. which include the I will definitely continue to buy from this site. an invaluable I will recommend this site to my friends. Thanks!
    cheap louis vuitton outlet https://www.cheapreallouisvuitton.com/

  6. cheap louis vuitton outlet

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

  7. louis vuitton outlet online

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

  8. cheap jordans online

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

  9. louis vuittons outlet

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

  10. cheap jordans for sale

    Read reviews and was a little hesitant since I had already inputted my order. potentially but thank god, I had no issues. similar to 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 jordans for sale https://www.realjordansshoes.com/

  11. invoimi

    This study is also relevant as more and more data is coming in favor of freeze- thawed embryo transfers achat levitra au usa Metabolic reprogramming is a staple of cancer cell growth and proliferation

  12. invoimi

    what is in viagra RT PCR showed that Gli3 was expressed in FF, FO and CV papillae taste tissue, as well as in lingual epithelium devoid of taste buds Fig 1A

  13. galNgfjye

    viagra alternatives over the counter Individuals with FAP may develop soft tissue tumors desmoid tumors in the mesentery, abdominal wall or areas of scars

  14. JwhLLWeU

    propecia vs finasteride Survey of vaginitis nsv

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

已运行:

访问量:510519