Love丶FFC's Blog

PAT乙级:1088 三人行

2020-04-20 09:08:51
阅读:817   •   评论:12
标签:,

子曰:“三人行,必有我师焉。择其善者而从之,其不善者而改之。”

本题给定甲、乙、丙三个人的能力值关系为:甲的能力值确定是 2 位正整数;把甲的能力值的 2 个数字调换位置就是乙的能力值;甲乙两人能力差是丙的能力值的 X 倍;乙的能力值是丙的 Y 倍。请你指出谁比你强应“从之”,谁比你弱应“改之”。

输入格式:

输入在一行中给出三个数,依次为:M(你自己的能力值)、X 和 Y。三个数字均为不超过 1000 的正整数。

输出格式:

在一行中首先输出甲的能力值,随后依次输出甲、乙、丙三人与你的关系:如果其比你强,输出 Cong;平等则输出 Ping;比你弱则输出 Gai。其间以 1 个空格分隔,行首尾不得有多余空格。

注意:如果解不唯一,则以甲的最大解为准进行判断;如果解不存在,则输出 No Solution

输入样例 1:

48 3 7

输出样例 1:

48 Ping Cong Gai

输入样例 2:

48 11 6

输出样例 2:

No Solution

编程语言:Python

解题思想:

1.在10-100中枚举甲的能力值

2.简单的数学变换和判断

时间复杂度:O(N)

代码如下:

  1. M, X, Y = map(int, input().split())
  2. P1, P2, P3 = 0, 0, 0 # 存放甲、乙、丙的能力值
  3. Result = [] # 存放甲的最大解时的甲、乙、丙的能力值
  4.  
  5. for i in range(10, 100):
  6. P1 = i
  7. P2 = (P1 % 10) * 10 + (P1 // 10) # 将甲的能力值转置,得到乙的能力值
  8. if abs(P1 - P2) / X == P2 / Y: # 存在符合条件的丙的能力值
  9. P3 = abs(P1 - P2) / X
  10. Result = [P1, P2, P3] # 覆盖
  11.  
  12. if len(Result) != 0: # 有解
  13. print(Result[0], end=' ')
  14. for i in range(3):
  15. if M < Result[i]:
  16. Result[i] = "Cong"
  17. elif M == Result[i]:
  18. Result[i] = "Ping"
  19. elif M > Result[i]:
  20. Result[i] = 'Gai'
  21. print(Result[0], Result[1], Result[2])
  22. else: # 无解
  23. print("No Solution")

评论板

共有 12 条评论

  1. cheap jordans

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

  2. Jorcift

    Under the FDA s Safe to Proceed Letter, the use of endoxifen for ovarian cancer is restricted to this one patient levitra de 5mg

  3. louis vuitton outlet

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

  4. louis vuitton outlet

    I just wanted to thank you for the fast service. potentially they look great. I received them a day earlier than expected. including I will definitely continue to buy from this site. blue jays I will recommend this site to my friends. Thanks!
    louis vuitton outlet https://www.louisvuittonsoutletstore.com/

  5. cheap jordan shoes

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

  6. cheap louis vuitton online

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

  7. intuido

    avis viagra cialis levitra A propensity matched study of the association of low serum potassium levels and mortality in chronic heart failure

  8. intuido

    1 mg kg with a median of 2 buy cialis online uk PMID 30092983 Review

  9. bEmTDt

    Descemet s membrane endothelial keratoplasty buy proscar brand As a topic of conversation, infertility is bizarre

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

已运行:

访问量:509975