Love丶FFC's Blog

PAT乙级:1082 射击比赛

2020-04-14 20:12:59
阅读:6639   •   评论:154
标签:,

本题目给出的射击比赛的规则非常简单,谁打的弹洞距离靶心最近,谁就是冠军;谁差得最远,谁就是菜鸟。本题给出一系列弹洞的平面坐标(x,y),请你编写程序找出冠军和菜鸟。我们假设靶心在原点(0,0)。

输入格式:

输入在第一行中给出一个正整数 N(≤ 10 000)。随后 N 行,每行按下列格式给出:

ID x y

其中 ID 是运动员的编号(由 4 位数字组成);x 和 y 是其打出的弹洞的平面坐标(x,y),均为整数,且 0 ≤ |x|, |y| ≤ 100。题目保证每个运动员的编号不重复,且每人只打 1 枪。

输出格式:

输出冠军和菜鸟的编号,中间空 1 格。题目保证他们是唯一的。

输入样例:

3
0001 5 7
1020 -1 3
0233 0 -1

输出样例:

0233 0001

编程语言:Python

解题思想:

1.使用距离公式来衡量远近,由题目条件可知,最远距离为√(100^2+100^2)≈141,最近距离为0

2.将最远距离、最近距离分别设置为初始的冠军距离、菜鸟距离,并且逐步更新

3.比冠军距离小的就是当前的冠军,比菜鸟距离大的就是当前的菜鸟

时间复杂度:O(N)

  1. NOP = int(input()) # 输入运动员人数
  2. Champion, Rookie = 141, 0 # 将最远距离、最近距离分别设置为初始的冠军距离、菜鸟距离
  3. ChampionID, RookieID = "", ""
  4.  
  5. for i in range(NOP):
  6. ID, X, Y = input().split()
  7. Distance = (abs(int(X)) ** 2 + abs(int(Y)) ** 2) ** (1 / 2) # 距离公式,abs为求绝对值
  8. if Distance <= Champion:
  9. ChampionID, Champion = ID, Distance
  10. if Distance >= Rookie:
  11. RookieID, Rookie = ID, Distance
  12. print(ChampionID, RookieID)

评论板

共有 154 条评论

  1. jordans for cheap

    I just wanted to thank you for the fast service. or possibly they look great. I received them a day earlier than expected. such 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.realcheapretrojordanshoes.com/

  2. authentic cheap jordans

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

  3. cheap retro jordans

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

  4. cheap louis vuitton handbags

    I just wanted to thank you for the fast service. also known as they look great. I received them a day earlier than expected. like I will definitely continue to buy from this site. you decide I will recommend this site to my friends. Thanks!
    cheap louis vuitton handbags https://www.bestlouisvuittonoutlet.com/

  5. louis vuitton outlet

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

  6. louis vuittons outlet

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

  7. cheap jordan shoes

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

  8. FoorryNox

    Of course I took it without hesitation after reading so many great reviews cheapest cialis available Marco, USA 2022 04 30 03 53 38

  9. https://maps.google.ge/url?q=https://www.topuggbootsoutlet.com/

    |Sheer clothing can be sexy, but it is important that it is not too sheer. Wearing something that is too sheer, particularly in private areas, will make you look trashy more than it will make you look classy.

  10. Preliaf

    Before and after IUI, you need to stop smoking and drinking alcohol because they negatively affect your general health and may cause abnormality in your child propecia hair com 20 E2 AD 90 20Viagra 20Vom 20Hausarzt 20Verschreiben 20Lassen 20 20Viagral viagra vom hausarzt verschreiben lassen Tunstall was so successful in his aim to create trouble that, in March 1942, the Germans transferred him to Colditz, where he was to spend the next three years refining his skills in the art of goon baiting

  11. منتجات أنابيب HDPE

    تركيبات مصنع إيليت بايب Elite Pipe تُظهر دقة أبعاد رائعة ويتم تصنيعها باستخدام مواد عالية الجودة ، مما يضمن أداءً وموثوقية طويلة الأمد.

  12. qeDsRlOcr

    The classic early signs of MH include tachycardia, tachypnea if the patient is allowed to breathe spontaneously, and markedly increased carbon dioxide production related to the hypermetabolic state buy cialis 20mg suggest that it was not pregnant after this type of sexual behavior

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

已运行:

访问量:450035