2024年2月CCF-全国精英算法大赛题目
我药打十个 2024-06-17 10:05:04 阅读 81
第一次参加这种比赛,虽然是c类赛事,但是是ccf主办的,难度还是有点的,主要是前面签到题主要是思想,后面的题目难度太高,身为力扣只刷了一百多道题目的我解决不了,这几道我只做了B,C题,E题超时了,这些题目的时间限制实在是太高了,这次只能是来学习学习了。顺便附上一下自己的代码,有点丑勿喷,希望有大神能出个题解,感谢
A题:
B题:
if __name__ in '__main__': Input = input() n,m = int(Input.split(' ')[0]),int(Input.split(' ')[1]) MIN = min(n,m) MAX = max(n,m) first_x = MIN first_y = MIN if n == m: k = 1 else: k = 2 if n<m else 3 for i in range(2): if k == 0: distance = min(n-first_x,m-first_y) first_x += distance first_y += distance elif k == 1: distance = min(first_x,first_y) first_x -= distance first_y -= distance elif k == 2: distance = min(first_x,m-first_y) first_x -= distance first_y += distance elif k == 3: distance = min(n-first_x,first_y) first_x += distance first_y -= distance flag = 0 if first_x == 0 and first_y == 0: k = 0 flag = 1 elif first_x == 0 and first_y == m: k = 3 flag = 1 elif first_x == n and first_y == 0: k = 2 flag = 1 elif first_x == n and first_y == m: k = 1 flag = 1 if flag == 0: if k == 0: if first_y == m: k = 3 elif first_x == n: k = 2 elif k == 1: if first_x == 0: k = 3 elif first_y == 0: k = 2 elif k == 2: if first_x == 0: k = 0 elif first_y == m: k = 1 elif k == 3: if first_y == 0: k = 0 elif first_x == n: k = 1 print(first_x,first_y)
C题:
if __name__ in '__main__': Input = input() n,m = int(Input.split(' ')[0]),int(Input.split(' ')[1]) n += 1 top = 1 while((n ** top) <= m): top += 1 top -= 1 temp = top nums = [] while(top > 0): num = m // (n**top) m -= num * (n**top) nums.append(num) top -= 1 if m > 0: nums.append(m) res = '' for i, snum in enumerate(nums): if snum == 0: temp -= 1 continue if temp > 1 and snum > 1: res += str(snum) + 'x^' + str(temp) + '+' elif temp > 1 and snum == 1: res += 'x^' + str(temp) + '+' elif temp == 1 and snum > 1: res += str(snum) + 'x+' elif temp == 1 and snum == 1: res += 'x+' else: res += str(snum) temp -= 1 print(res)
D题:
E题:
import mathdef check(num): if num == 2 or num == 3: return True end = num ** (1/2) for i in range(2,int(end)+1): if num % i == 0: return False if num == 1: return False return Trueif __name__ in '__main__': n = int(input()) res = 0 for i in range(2,n): if check(i): if check(n-i) == False: if n-i != 1: res += 2 else: res += 1 end = n-i start = 2 while(start < end): if (n-i) % start == 0: res += 2 end /= start start += 1 print(res)
F题:
G题:
H题:
I题:
希望这篇博客对你有帮助,希望有大神出一下题解!!!!
上一篇: Java 类与对象 -- Java 语言的类与对象、构造器、static、final、包和 JAR
下一篇: 华为OD机试C卷-- 找城市(Java & JS & Python & C)
本文标签
声明
本文内容仅代表作者观点,或转载于其他网站,本站不以此文作为商业用途
如有涉及侵权,请联系本站进行删除
转载本站原创文章,请注明来源及作者。