当前位置:   article > 正文

2024年2月CCF-全国精英算法大赛题目_2024算法竞赛

2024算法竞赛

第一次参加这种比赛,虽然是c类赛事,但是是ccf主办的,难度还是有点的,主要是前面签到题主要是思想,后面的题目难度太高,身为力扣只刷了一百多道题目的我解决不了,这几道我只做了B,C题,E题超时了,这些题目的时间限制实在是太高了,这次只能是来学习学习了。顺便附上一下自己的代码,有点丑勿喷,希望有大神能出个题解,感谢

A题:

B题:

  1. if __name__ in '__main__':
  2. Input = input()
  3. n,m = int(Input.split(' ')[0]),int(Input.split(' ')[1])
  4. MIN = min(n,m)
  5. MAX = max(n,m)
  6. first_x = MIN
  7. first_y = MIN
  8. if n == m:
  9. k = 1
  10. else:
  11. k = 2 if n<m else 3
  12. for i in range(2):
  13. if k == 0:
  14. distance = min(n-first_x,m-first_y)
  15. first_x += distance
  16. first_y += distance
  17. elif k == 1:
  18. distance = min(first_x,first_y)
  19. first_x -= distance
  20. first_y -= distance
  21. elif k == 2:
  22. distance = min(first_x,m-first_y)
  23. first_x -= distance
  24. first_y += distance
  25. elif k == 3:
  26. distance = min(n-first_x,first_y)
  27. first_x += distance
  28. first_y -= distance
  29. flag = 0
  30. if first_x == 0 and first_y == 0:
  31. k = 0
  32. flag = 1
  33. elif first_x == 0 and first_y == m:
  34. k = 3
  35. flag = 1
  36. elif first_x == n and first_y == 0:
  37. k = 2
  38. flag = 1
  39. elif first_x == n and first_y == m:
  40. k = 1
  41. flag = 1
  42. if flag == 0:
  43. if k == 0:
  44. if first_y == m:
  45. k = 3
  46. elif first_x == n:
  47. k = 2
  48. elif k == 1:
  49. if first_x == 0:
  50. k = 3
  51. elif first_y == 0:
  52. k = 2
  53. elif k == 2:
  54. if first_x == 0:
  55. k = 0
  56. elif first_y == m:
  57. k = 1
  58. elif k == 3:
  59. if first_y == 0:
  60. k = 0
  61. elif first_x == n:
  62. k = 1
  63. print(first_x,first_y)

C题:

  1. if __name__ in '__main__':
  2. Input = input()
  3. n,m = int(Input.split(' ')[0]),int(Input.split(' ')[1])
  4. n += 1
  5. top = 1
  6. while((n ** top) <= m):
  7. top += 1
  8. top -= 1
  9. temp = top
  10. nums = []
  11. while(top > 0):
  12. num = m // (n**top)
  13. m -= num * (n**top)
  14. nums.append(num)
  15. top -= 1
  16. if m > 0:
  17. nums.append(m)
  18. res = ''
  19. for i, snum in enumerate(nums):
  20. if snum == 0:
  21. temp -= 1
  22. continue
  23. if temp > 1 and snum > 1:
  24. res += str(snum) + 'x^' + str(temp) + '+'
  25. elif temp > 1 and snum == 1:
  26. res += 'x^' + str(temp) + '+'
  27. elif temp == 1 and snum > 1:
  28. res += str(snum) + 'x+'
  29. elif temp == 1 and snum == 1:
  30. res += 'x+'
  31. else:
  32. res += str(snum)
  33. temp -= 1
  34. print(res)

D题:

E题:

  1. import math
  2. def check(num):
  3. if num == 2 or num == 3:
  4. return True
  5. end = num ** (1/2)
  6. for i in range(2,int(end)+1):
  7. if num % i == 0:
  8. return False
  9. if num == 1:
  10. return False
  11. return True
  12. if __name__ in '__main__':
  13. n = int(input())
  14. res = 0
  15. for i in range(2,n):
  16. if check(i):
  17. if check(n-i) == False:
  18. if n-i != 1:
  19. res += 2
  20. else:
  21. res += 1
  22. end = n-i
  23. start = 2
  24. while(start < end):
  25. if (n-i) % start == 0:
  26. res += 2
  27. end /= start
  28. start += 1
  29. print(res)

F题:

G题:

H题:

I题:

希望这篇博客对你有帮助,希望有大神出一下题解!!!!

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/盐析白兔/article/detail/544411
推荐阅读
相关标签
  

闽ICP备14008679号