CCF 2017年题目题解 - Python
生活随笔
收集整理的這篇文章主要介紹了
CCF 2017年题目题解 - Python
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
2017年刷題目錄
- 2017年12月
- 201712-1 最小差值
- 題目鏈接:
- 代碼:
- 易錯點需注意點:
- 201712-2 游戲
- 題目鏈接:
- 代碼:
- 易錯點需注意點:直接模擬!
- 201712-3
- 題目鏈接:
- 代碼:
- 易錯點需注意點:
- 2017年09月
- 201709-1 打醬油
- 題目鏈接:
- 代碼:
- 易錯點需注意點:
- 201709-2 公共鑰匙盒
- 題目鏈接:
- 代碼:
- 易錯點需注意點:
- 201709-3
- 題目鏈接:
- 代碼:
- 易錯點需注意點:
- 2017年03月
- 201703-1 分蛋糕
- 題目鏈接:
- 代碼:
- 201703-2 學生排隊
- 題目鏈接:
- 代碼:
- 易錯點需注意點:
- 201703-3
- 題目鏈接:
- 代碼:
- 易錯點需注意點:
2017年12月
201712-1 最小差值
題目鏈接:
http://118.190.20.162/view.page?gpid=T68
代碼:
n = int(input()) l = list(map(int,input().split())) l = sorted(l) min = 99999 for i in range(1,n):if abs(l[i]-l[i-1])<min:min = abs(l[i]-l[i-1]) print(min)易錯點需注意點:
201712-2 游戲
題目鏈接:
http://118.190.20.162/view.page?gpid=T67
代碼:
n,k = map(int,input().split()) number = 0 #記錄現在數到幾了 tag = [1 for i in range(n)] x = 0 while sum(tag) != 1:if tag[x] != 0:number += 1if number%k==0 or str(number)[-1] == str(k):tag[x] = 0x = (x+1)%n print(tag.index(1)+1)易錯點需注意點:直接模擬!
201712-3
題目鏈接:
代碼:
易錯點需注意點:
2017年09月
201709-1 打醬油
題目鏈接:
http://118.190.20.162/view.page?gpid=T63
代碼:
import math n = int(input()) count = 0 while n!=0:if n >= 50:c = math.floor(n/50)count += (c*7)n -= c*50elif n>=30:c = math.floor(n / 30)count += (c * 4)n -= c * 30else:c = math.floor(n / 10)count += (c*1)n -= c*10 print(count)易錯點需注意點:
201709-2 公共鑰匙盒
題目鏈接:
http://118.190.20.162/view.page?gpid=T62
代碼:
n,k = map(int,input().split()) keys = [i for i in range(1,n+1)] time_list = [] schedule = {} #True借 False還 for i in range(k):w,s,c = map(int,input().split())if s not in time_list:time_list.append(s)if s+c not in time_list:time_list.append(s+c)if s in schedule:schedule[s].append([w,True])else:schedule[s] = [[w,True]]if s+c in schedule:schedule[s+c].append([w, False])else:schedule[s+c] = [[w, False]] time_list = sorted(time_list) for time in time_list:schedule[time] = sorted(schedule[time],key=lambda x:(x[1],x[0]))for t in schedule[time]:if t[1] == False: #還keys[keys.index(0)] = t[0]elif t[1] == True: #借keys[keys.index(t[0])] = 0 print(" ".join(map(str,keys)))易錯點需注意點:
1)借和還的True、False設置需要注意 sorted排序時默認將False排在前面,因此根據題目中要求的先還再借,我們要把還設置成False
2)sorted自定義排序中設置兩個關鍵字輔助排序需要用括號括上,如:sorted(list,key=lambda x:(x[0],x[1]))
201709-3
題目鏈接:
代碼:
易錯點需注意點:
2017年03月
201703-1 分蛋糕
題目鏈接:
http://118.190.20.162/view.page?gpid=T57
代碼:
n,k = map(int,input().split()) l = list(map(int,input().split())) count = 0 now_weight = 0 for i in range(n):now_weight += l[i]if now_weight < k and i == n-1: count += 1elif now_weight < k:passelse:count += 1now_weight = 0 print(count)201703-2 學生排隊
題目鏈接:
http://118.190.20.162/view.page?gpid=T56
代碼:
n = int(input()) m = int(input()) students = [i for i in range(1,n+1)] info = [] for i in range(m):p,q = map(int,input().split())s = students.index(p)if s+q == n:students.remove(p)students.append(p)elif s+q == 0:students.remove(p) #remove值 pop位置students.insert(0,p)else:students.remove(p)students.insert(s+q,p) print(" ".join(map(str,students)))易錯點需注意點:
注意范圍!!
201703-3
題目鏈接:
代碼:
易錯點需注意點:
總結
以上是生活随笔為你收集整理的CCF 2017年题目题解 - Python的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: CCF 2018年题目题解 - Pyth
- 下一篇: CCF 2016年题目题解 - Pyth