100分值题
- 小朋友来自多少小区
- 堆内存申请
- 跳格子3
- 测试用例执行计划
小朋友来自多少小区
nums = [int(x) for x in input().split(" ")]
#index为报告的结果,zones[index]为报告相同结果的总人数
zones = [0 for x in range(1000)]
count = 0
i=0
while(True):
if(i>=len(nums)):
break
else:
zones[nums[i]]+=1
i+=1
for j in range(1000):
if (zones[i] <= 0):
continue
else:
total = math.ceil(zones[j] / (j+1));
count += total * (j+1);
print(count);
堆内存申请
n = int(input())
memorys = []
while (True) :
try:
nums = [int(x) for x in input().split(" ")]
memorys.append([nums[0], nums[0]+nums[1]- 1])
except:
break
memorys.sort()
length = len(memorys)
flag = 0
for i in range(length):
x = memorys[i][0]
y = memorys[i][1]
if (not ((x >= 0 and y >= 0 and x < 100 and y < 100 and x <= y) and
(not (i > 0 and x <= memorys[i-1][1])))) :
flag = 1
break
if (flag!=1) :
offset = -1
max_distance = 100
start = memorys[0][0]
if (start >= n and start < max_distance + n) :
offset = 0
max_distance = start - n
i=1
while(True):
if(i>=length):
break
else :
current = memorys[i][0]
before = memorys[i-1][1]
if (current - before > n):
if(current - before < max_distance + n) :
offset = before + 1
max_distance = current - before - n
break
i+=1
end = memorys[length - 1][1]
if (end<=99-n and end > 99-n-max_distance) :
offset = end + 1
print(offset)
else:
print(-1)
跳格子3
n =int(input())
nums = [int(x) for x in input().split(" ")]
k = int(input())
queue = [[0 for i in range(2)] for j in range(n)]
cache =[0 for i in range(n)]
cache[0] = nums[0]
queue[0][0] = 0
queue[0][1] = cache[0]
index1 = 0
index2 = 1
i=1
while(True):
if(i>=n):
break
else :
while(index1<index2):
if(queue[index1][0] < i - k):
index1 +=1
else :
break
cache[i] = nums[i] + queue[index1][1]
while(index1<index2):
if(queue[index1][1] <= cache[i]):
index1 +=1
else :
break
queue[index2][0] = i
queue[index2][1] = cache[i]
index2+=1
i+=1
print(cache[n - 1])
测试用例执行计划
import functools
import sys
import copy
import re
import math
import queue
nums = [int(x) for x in input().split(" ")]
n = nums[0]
m = nums[1]
prioritys = []
for i in range(n):
prioritys.append(int(input()))
list_a =[]
for i in range(m):
nums1 = [int(x) for x in input().split(" ")]
total = 0
for j in range(len(nums1)):
total += prioritys[nums1[j]-1]
list_a.append([i + 1, total])
list_a =sorted(list_a, key=lambda x : (-x[1],x[0]))
for i in range(len(list_a)):
print(list_a[i][0])