第一题 1A

A. Theatre Square
time limit per test

2 seconds

memory limit per test

64 megabytes

input

standard input

output

standard output

Theatre 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.

Input

The input contains three positive integer numbers in the first line: n, m and a (1 ≤ n, m, a ≤ 109).

Output

Write the needed number of flagstones.

Sample test(s)
input
6 6 4
output
4

题意:给一个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

A. Winner
time limit per test

1 second

memory limit per test

64 megabytes

input

standard input

output

standard output

The 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.

Input

The 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.

Output

Print the name of the winner.

Sample test(s)
input
3
mike 3
andrew 5
mike 2
output
andrew
input
3
andrew 3
andrew 2
mike 5
output
andrew

题意:有很多人在玩纸牌游戏,总共玩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的更多相关文章

  1. 《用Python解决数据结构与算法问题》在线阅读

    源于经典 数据结构作为计算机从业人员的必备基础,Java, c 之类的语言有很多这方面的书籍,Python 相对较少, 其中比较著名的一本 problem-solving-with-algorithm ...

  2. 有关科学计算方面的python解决

    在科学计算方面,一般觉得matlab是一个超强的东西.此外还有R. 至于某种语言来说,一般都要讲究一些特别的算法,包含但不限于: 矩阵方面的计算 指数计算 对数计算 多项式运算 各类方程求解 总之.仅 ...

  3. appium+python解决每次运行代码都提示安装Unlock以及AppiumSetting的问题

    appium+python解决每次运行代码都提示安装Unlock以及AppiumSetting的问题(部分安卓机型) 1.修改appium-android-driver\lib下的android-he ...

  4. 高德API+Python解决租房问题(.NET版)

    源码地址:https://github.com/liguobao/58HouseSearch 在线地址:58公寓高德搜房(全国版):http://codelover.link:8080/ 周末闲着无事 ...

  5. python笔记-用python解决小学生数学题【转载】

    本篇转自博客:上海-悠悠 原文地址:http://www.cnblogs.com/yoyoketang/tag/python/ 前几天有人在群里给小编出了个数学题: 假设你有无限数量的邮票,面值分别为 ...

  6. v&n赛 ML 第一步(python解决)

    题目链接 给了70组x,y,根据提示,是求拟合曲线,再通过x求y 知道MATLAB应该录入就能解决吧,但是没下这软件,试试用python解决 #coding:utf- from pwn import ...

  7. 用 python 解决线性代数中的矩阵运算

    用 python 解决线性代数中的矩阵运算 矩阵叉乘 矩阵求逆 矩阵转置 假定AX=B,求解未知矩阵X 矩阵的行列式值|matrix| 未完待续..... import sys from PyQt5. ...

  8. 用python解决打标签时将xml文件的标签名打错

    用python解决打标签时将xml文件的标签名打错 问题描述:再进行达标签时将magnetic_tile的标签名错误的打成了magnetic_title,又不想一张一张的修改 出现问题的xml文件 & ...

  9. Python解决八皇后问题

    最近看Python看得都不用tab键了,哈哈.今天看了一个经典问题--八皇后问题,说实话,以前学C.C++的时候有这个问题,但是当时不爱学,没搞会,后来算法课上又碰到,只是学会了思想,应该是学回溯法的 ...

随机推荐

  1. 微软阵营企稳的利好消息:.NET开源、Visual Studio免费

    今天各个IT社区,头版头条说的是微软.NET开源了.宇宙中最好的IED–Visual Studio Community 2013将免费提供给用户的消息. <宇宙中最强大的开发环境免费了!> ...

  2. Core Animation之CABasicAnimation

    在iOS中,图形可分为以下几个层次: 越上层,封装程度越高,动画实现越简洁越简单,但是自由度越低:反之亦然.本文着重介绍Core Animation层的基本动画实现方案. 在iOS中,展示动画可以类比 ...

  3. FlashBuilder启动时一闪而过

    晚上的时候把项目目录直接剪切走了 早晨就打不开了 去workspace看log  .\workspace\.metadata\.log 发现如下代码!MESSAGE Could not read me ...

  4. OpenJudge/Poj 1915 Knight Moves

    1.链接地址: http://bailian.openjudge.cn/practice/1915 http://poj.org/problem?id=1915 2.题目: 总Time Limit: ...

  5. 24种设计模式--中介者模式【Mediator Pattern】

    各位好,大家都是来自五湖四海,都要生存,于是都找了个靠山——公司,给你发薪水的地方,那公司就要想尽办法盈利赚钱,盈利方法则不尽相同,但是作为公司都有相同三个环节:采购.销售和库存,这个怎么说呢?比如一 ...

  6. redis 入门笔记(一)

    redis是一个开源,先进的key-value存储,并用于构建高性能,可扩展的web应用程序的完美解决方案 三个主要特点:      1,Redis数据库完全在内存中,使用磁盘仅用于持久性       ...

  7. FBWF和EWF的对比

    最近在公司接触了嵌入式的wes7系统,wes7和wes2009是组件化的windows系统,除具有最新版的windows功能之外还具有适用于嵌入式系统的一些嵌入式功能,如例如EWF,FBWF. FBW ...

  8. nginx错误日志error_log日志级别

    error_log 级别分为 debug, info, notice, warn, error, crit  默认为crit,

  9. 捕获ClientDataSet.ApplyUpdates和SocketConnection异常

    核心提示:如何捕获ClientDataSet.ApplyUpdates的错误,不用ReconcileError... var cdsEmp:TClientDataSet; //保存 procedure ...

  10. C#中的==、Equal、ReferenceEqual(转载)

    1. ReferenceEquals, == , Equals Equals , == , ReferenceEquals都可以用于判断两个对象的个体是不是相等. a) ReferenceEquals ...