Python解决codeforces ---- 1
第一题 1A
A. Theatre Squaretime limit per test2 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard outputTheatre Square in the capital city of Berland has a rectangular shape with the size n?×?m meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size a?×?a.
What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square.
InputThe input contains three positive integer numbers in the first line: n,??m and a (1?≤??n,?m,?a?≤?109).
OutputWrite the needed number of flagstones.
Sample test(s)input6 6 4output
4
题意:给一个n*m的矩形,和a*a的正方形。要用a*a的正方形去覆盖n*m的矩形,要求a*a的正方形不能切割开,但是两个a*a的正方形可以重叠,问最小需要几个这样的正方形
代码:
A. Winnertime limit per test1 secondmemory limit per test64 megabytesinputstandard inputoutputstandard outputThe winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a player gains or loses a particular number of points. In the course of the game the number of points is registered in the line "name score", where name is a player's name, and score is the number of points gained in this round, which is an integer number. If score is negative, this means that the player has lost in the round. So, if two or more players have the maximum number of points (say, it equals to m) at the end of the game, than wins the one of them who scored at least m points first. Initially each player has 0 points. It's guaranteed that at the end of the game at least one player has a positive number of points.
InputThe first line contains an integer number n (1??≤??n??≤??1000), n is the number of rounds played. Then follow n lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is an integer number between -1000 and 1000, inclusive.
OutputPrint the name of the winner.
Sample test(s)input3mike 3andrew 5mike 2outputandrewinput3andrew 3andrew 2mike 5outputandrew题意:有很多人在玩纸牌游戏,总共玩n轮。每一轮里面包括玩家的名字,和玩家这一轮的得分,现在问最后谁的得分最高(假设为m),如果有多个人得分最高,输出最先得到m分的玩家
思路:我们先利用n轮求出最后每个人的得分这样就可以求出最大的分数m,然后枚举这么多个人去找如果得分为m的人就去从头模拟一遍找到得分为m分的轮数,最后找到赢家
代码:
# define some variablen = int(raw_input())maxScore = {}input = []# n times inputwhile 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 = ansans = 0for key in maxScore: ans = max(ans , maxScore[key])# def to find the time >= ansdef 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 == anstime = 2147483647for key in maxScore: if maxScore[key] == ans: t = getTime(key) if time > t: time = t ansName = key# outputprint ansName
第三题
第四题
第五题