执行时长
def min_execution_time(n, size, tasks):
a = 0
ans = size
i = 0
while i < size:
tmp = tasks[i]
a += tmp
if a < n:
a = 0
else:
a -= n
i += 1
ans += a // n
if a % n != 0:
ans += 1
return ans
# 读取输入
n = int(input())
size = int(input())
tasks = list(map(int, input().split()))
# 输出结果
result = min_execution_time(n, size, tasks)
print(result)
万能字符单词拼写
def count_valid_words(words_count, word_arr, chars):
char_arr = [0] * 26
any_num = 0
res = 0
for c in chars:
if c == '?':
any_num += 1
else:
char_arr[ord(c) - ord('a')] += 1
for word in word_arr:
word_split = [0] * 26
for c in word:
word_split[ord(c) - ord('a')] += 1
need_any_num = sum(max(0, word_split[i] - char_arr[i]) for i in range(26))
if need_any_num <= any_num:
res += 1
return res
if __name__ == "__main__":
words_count = int(input())
word_arr = [input() for _ in range(words_count)]
chars = input()
result = count_valid_words(words_count, word_arr, chars)
print(result)
来自异国的客人
有位客人来自异国,在该国使用m进制计数。该客人有个幸运数字n(n<m),每次购物时,其总是喜欢计算本次支付的花费(折算为异国的价格后)中存在多少幸运数字。问:当其购买一个在我国价值k的产品时,其中包含多少幸运数字?
输入描述
第一行输入为 k, n, m。
其中:
k 表示 该客人购买的物品价值(以十进制计算的价格)
n 表示 该客人的幸运数字
m 表示 该客人所在国度的采用的进制
输出描述
输出幸运数字的个数,行末无空格。当输入非法内容时,输出0
# coding:utf-8
#JSRUN引擎2.0,支持多达30种语言在线运行,全仿真在线交互输入输出。
import functools
import sys
from collections import Counter, defaultdict
import copy
from itertools import permutations
import re
import math
import sys
from queue import Queue
k=0
n=0
m=0
flag = False
try:
params = [int(x) for x in input().split(" ")]
k= params[0]
n = params[1]
m = params[2]
if(k <= 0 or n <= 0 or m <= 1 or n >= m):
print(0)
flag = True
except :
print(0)
flag = True
if(not flag) :
result = 0
while(True):
if(k<=0) :
print(result)
break
else :
if (k % m == n) :
result+=1
k //= m
else:
k //= m
求最多可以派出多少支团队
n = int(input())
v = list(map(int, input().split()))
t = int(input())
v.sort(reverse=True)
left = 0
right = n - 1
res = 0
while left < right:
if v[left] >= t:
res += 1
left += 1
else:
while left < right:
if v[left] + v[right] >= t:
left += 1
right -= 1
res += 1
break
right -= 1
print(res)
最长子字符串的长度(一)
import sys
for line in sys.stdin:
input_str = line.strip()
char_o_nums = input_str.count('o')
if char_o_nums % 2 == 0:
print(len(input_str))
else:
print(len(input_str) - 1)
机场航班调度程序
class Main:
@staticmethod
def schedule(mv):
ost = ""
for key, value in sorted(mv.items()):
for v in sorted(value):
ost += key + format(v, '04d') + ","
ans = ost[:-1] # Remove the trailing comma
return ans
@staticmethod
def main():
s = input()
s = s.replace(",", " ")
tokens = s.split()
mv = {}
for token in tokens:
key = token[:2]
value = int(token[2:])
if key not in mv:
mv[key] = []
mv[key].append(value)
print(Main.schedule(mv))
Main.main()
数的分解
def find_consecutive_sum(n):
result = []
start = 1
end = 2
while start < end:
current_sum = (start +end) * (end - start +1)//2
if current_sum == n:
result.append(list(range(start,end + 1)))
start += 1
elif current_sum < n:
end += 1
else:
start += 1
if result:
min_length = min(len(seq) for seq in result)
for seq in result:
if len(seq) == min_length:
return f"{n}={'+'.join(str(i)for i in seq)}"
else:
return "N"
n = int(input())
print (find_consecutive_sum(n))