概述
第一题 1A
题意:给一个n*m的矩形,和a*a的正方形。要用a*a的正方形去覆盖n*m的矩形,要求a*a的正方形不能切割开,但是两个a*a的正方形可以重叠,问最小需要几个这样的正方形
代码:
my_list = raw_input().split()
n = int(my_list[0])
m = int(my_list[1])
a = int(my_list[2])
print (n/a+(n%a>0))*(m/a+(m%a>0))
第二题 2A
题意:有很多人在玩纸牌游戏,总共玩n轮。每一轮里面包括玩家的名字,和玩家这一轮的得分,现在问最后谁的得分最高(假设为m),如果有多个人得分最高,输出最先得到m分的玩家
思路:我们先利用n轮求出最后每个人的得分这样就可以求出最大的分数m,然后枚举这么多个人去找如果得分为m的人就去从头模拟一遍找到得分为m分的轮数,最后找到赢家
代码:
# define some variable
n = int(raw_input())
maxScore = {}
input = []
# n times input
while n > 0:
list = raw_input().split()
input.append(list)
name = list[0]
score = int(list[1])
if maxScore.has_key(name):
maxScore[name] += score
else:
maxScore[name] = score
n -= 1
# find maxScore = ans
ans = 0
for key in maxScore:
ans = max(ans , maxScore[key])
# def to find the time >= ans
def getTime(str):
sum = 0
cnt = 0
for list in input:
name = list[0]
score = int(list[1])
if name == str:
sum += score
if sum >= ans:
return cnt
cnt += 1
# one by one if score == ans
time = 2147483647
for key in maxScore:
if maxScore[key] == ans:
t = getTime(key)
if time > t:
time = t
ansName = key
# output
print ansName
第三题
第四题
第五题
最后
以上就是热心麦片为你收集整理的Python解决codeforces ---- 1的全部内容,希望文章能够帮你解决Python解决codeforces ---- 1所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复