Love丶FFC's Blog

PAT乙级:1032 挖掘机技术哪家强

2020-02-22 10:56:24
阅读:8157   •   评论:149
标签:,

为了用事实说明挖掘机技术到底哪家强,PAT 组织了一场挖掘机技能大赛。现请你根据比赛结果统计出技术最强的那个学校。

输入格式:

输入在第 1 行给出不超过 10​5​​ 的正整数 N,即参赛人数。随后 N 行,每行给出一位参赛者的信息和成绩,包括其所代表的学校的编号(从 1 开始连续编号)、及其比赛成绩(百分制),中间以空格分隔。

输出格式:

在一行中给出总得分最高的学校的编号、及其总分,中间以空格分隔。题目保证答案唯一,没有并列。

输入样例:

6
3 65
2 80
1 100
2 70
3 40
3 0

输出样例:

2 150

编程语言:Python、C

解题思想:

1.思考题目,会发现学校编号和列表下标可以有一一对应的关系,这样就不必每次都判断该编号是否出现过

2.使用动态扩展列表的方法,每当学校编号大于列表长度时,就根据差值扩展列表

3.输入的时候直接将Score赋给Number下标-1的元素即可

也许因为Python性能的缘故,最后一个测试点超时,在网上查阅了很多代码,依然无法解决,最后选择使用C来解决超时问题

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

代码如下(Python):

  1. NOP = int(input())
  2. School = list()
  3.  
  4. for i in range(NOP):
  5. Number, Score = map(int, input().split())
  6. if Number >= len(School) + 1: # 学校编号大于当前列表长度,注意学校编号-1=列表下标
  7. for j in range(Number - len(School)): # 根据学校编号与列表长度的差值动态扩展列表,例如出现了编号4,此时列表长度为2,就需要扩展4-2=2个长度
  8. School.append(0)
  9. School[Number - 1] += Score
  10. else:
  11. School[Number - 1] += Score
  12.  
  13. # 因为题目明确了答案唯一,所以利用max方法找出列表的最大值,再利用index方法找出最大值对应的下标,该下标+1就是学校编号
  14. print(School.index(max(School)) + 1, max(School))

代码如下(C):

  1. #include <stdio.h>
  2. int main()
  3. {
  4. int School[100000];
  5. for (int i=0;i < 100000;i++)
  6. {
  7. School[i] = 0;
  8. }
  9. int NOP;
  10. scanf("%d", & NOP);
  11. for (int i=0;i < NOP;i++)
  12. {
  13. int Number;
  14. int Score;
  15. scanf("%d %d", & Number, & Score);
  16. School[Number-1] += Score;
  17. }
  18. int Max=0;
  19. int MaxID;
  20. for (int i=0;i < 100000;i++)
  21. {
  22. if (School[i] > Max)
  23. {
  24. Max = School[i];
  25. MaxID = i;
  26. }
  27. }
  28. printf("%d %d", MaxID+1, Max);
  29. return 0;
  30. }

评论板

共有 149 条评论

  1. Abupguele

    FDA Living with Fibromyalgia, Drugs Approved to Manage Pain, Medical Guide for Nonsteroidal Anti Inflammatory Drugs NSAIDS cialis 5mg online 1 fat calories derived from soy oil

  2. Outlils

    propecia hair growth Tamoxifen daily dose and duration of treatment

  3. cheap louis vuitton bags

    I just wanted to thank you for the fast service. or it may be they look great. I received them a day earlier than expected. similar to I will definitely continue to buy from this site. blue jays I will recommend this site to my friends. Thanks!
    cheap louis vuitton bags https://www.bestlouisvuittonoutlet.com/

  4. authentic cheap jordans

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

  5. cheap jordans online

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

  6. cheap louis vuitton handbags

    Read reviews and was a little hesitant since I had already inputted my order. or even a but thank god, I had no issues. like 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.
    cheap louis vuitton handbags https://www.cheaplouisvuittonsale.com/

  7. louis vuitton outlet

    Read reviews and was a little hesitant since I had already inputted my order. or even but thank god, I had no issues. decline 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.
    louis vuitton outlet https://www.louisvuittonsoutletstore.com/

  8. cheap real jordans

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

  9. louis vuitton outlet online

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

  10. aol slot lounge play free slots

    online slots that pay real money free slots just for fun casino slots free games aol slot lounge play free slots

  11. online gambling for real money

    free signup bonus no deposit casino free bonus
    no deposit casino online casino with free signup bonus real money usa no
    deposit online gambling for real money

  12. online casino free signup bonus no deposit required

    online casino with free signup bonus real money usa free welcome bonus no
    deposit required free casinos bonus online casino free signup bonus no deposit required

  13. free no deposit casino

    online real money casino bonus no deposit play blackjack online money free no deposit casino

  14. sign up casino bonus

    best online casino welcome bonus top online casino biggest
    online casino bonus sign up casino bonus

  15. bovada online casino

    us online casinos online casino free spins real
    money casinos bovada online casino

  16. online casinos for us players

    best online casino real money free no deposit online casino signup bonus no deposit online casinos for us players

  17. no deposit casino online

    best no deposit bonus best online casino welcome bonus casino welcome bonuses no deposit casino online

  18. casino free bonus

    real money online casino win real money online casino games for real money casino free bonus

  19. best online casino welcome bonuses

    best online usa casinos real casino games online no deposit casino bonus best online casino welcome bonuses

  20. no deposit slots for real money

    casino sign up bonus no deposit online casino best bonus best usa
    online casinos no deposit slots for real money

  21. invoimi

    13, 292, 392 Again, it is important to mention that advanced and or metastatic disease places patients at an increased risk of TE propecia dosage 2015 Jul; 2 4 199 205

  22. https://cse.google.com.et/url?q=https://www.topraybansoutlet.com/

    |There are hundreds of thousands of hair accessory possibilities. You can choose from lots of options, including headbands, scrunchies, bows, barrettes and extensions. Include various hair accessories for practical and aesthetic purposes. The right hair accessory can set off an entire outfit. When you are going out on the town, choose a headband that compliments your outfit.

  23. https://cse.google.com.mm/url?sa=i&url=https://www.topuggbootsoutlet.com/

    |An easy way to keep hair off your neck and shoulders is to do a casual up-do. Long hair can sometimes be a hassle. If you have no time to spend with your hair, get an elastic hairband and pull your hair up into a bun. Even if it is a little messy, it will look cute.

  24. IyVfJLRX

    After a median follow up of 30 months, the median OS of the entire cohort was 42 months acheter levitra en connexion November 2016 saw the official opening of Liverpool2, an extension to the port that allows post Panamax vessels to dock in Liverpool

  25. jordan outlet

    An interesting dialogue is price comment. I believe that you should write extra on this subject, it won’t be a taboo topic but typically individuals are not enough to talk on such topics. To the next. Cheers

  26. off white outlet

    Nice post. I be taught one thing tougher on totally different blogs everyday. It’ll all the time be stimulating to learn content from other writers and apply a little something from their store. I抎 want to make use of some with the content on my blog whether you don抰 mind. Natually I抣l provide you with a link on your web blog. Thanks for sharing.

  27. off white jordan 1

    An fascinating discussion is price comment. I think that it is best to write more on this topic, it might not be a taboo topic however typically individuals are not enough to talk on such topics. To the next. Cheers

  28. jordan

    This really answered my problem, thank you!

  29. golden goose

    An interesting discussion is worth comment. I think that it is best to write more on this subject, it may not be a taboo subject but generally persons are not enough to talk on such topics. To the next. Cheers

  30. jordan shoes

    The following time I read a weblog, I hope that it doesnt disappoint me as a lot as this one. I imply, I know it was my option to read, but I actually thought youd have something attention-grabbing to say. All I hear is a bunch of whining about one thing that you may fix when you werent too busy on the lookout for attention.

  31. bape hoodie

    An impressive share, I simply given this onto a colleague who was doing slightly analysis on this. And he in fact bought me breakfast as a result of I discovered it for him.. smile. So let me reword that: Thnx for the treat! But yeah Thnkx for spending the time to debate this, I feel strongly about it and love studying extra on this topic. If possible, as you turn out to be experience, would you mind updating your blog with more particulars? It’s highly useful for me. Large thumb up for this weblog put up!

  32. kobe shoes

    Oh my goodness! a tremendous article dude. Thank you Nonetheless I’m experiencing issue with ur rss . Don抰 know why Unable to subscribe to it. Is there anybody getting similar rss drawback? Anyone who is aware of kindly respond. Thnkx

  33. supreme official

    You made some respectable factors there. I regarded on the web for the difficulty and found most people will associate with with your website.

  34. goyard tote bag

    I am often to blogging and i actually appreciate your content. The article has actually peaks my interest. I’m going to bookmark your site and keep checking for brand spanking new information.

  35. yeezy 700

    After study a few of the weblog posts on your web site now, and I really like your way of blogging. I bookmarked it to my bookmark website listing and can be checking back soon. Pls take a look at my web site as well and let me know what you think.

  36. pMKqud

    Definitions and assessment cialis for daily use

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

已运行:

访问量:452865