Python解决codeforces ---- 4

 第一题 10A

A. Power Consumption Calculation

time limit per test
1 second

memory limit per test
256 megabytes

input
standard input

output
standard output

Tom is interested in power consumption of his favourite laptop. His laptop has three modes. In normal mode laptop consumes P1 watt
per minute. T1 minutes
after Tom moved the mouse or touched the keyboard for the last time, a screensaver starts and power consumption changes to P2 watt
per minute. Finally, after T2 minutes
from the start of the screensaver, laptop switches to the "sleep" mode and consumes P3 watt
per minute. If Tom moves the mouse or touches the keyboard when the laptop is in the second or in the third mode, it switches to the first (normal) mode. Tom's work with the laptop can be divided into n time
periods [l1, r1], [l2, r2], ..., [ln, rn].
During each interval Tom continuously moves the mouse and presses buttons on the keyboard. Between the periods Tom stays away from the laptop. Find out the total amount of power consumed by the laptop during the period [l1, rn].

Input

The first line contains 6 integer numbers nP1, P2, P3, T1, T2 (1 ≤ n ≤ 100, 0 ≤ P1, P2, P3 ≤ 100, 1 ≤ T1, T2 ≤ 60).
The following nlines contain description of Tom's work. Each i-th
of these lines contains two space-separated integers li and ri (0 ≤ li < ri ≤ 1440, ri < li + 1 for i < n),
which stand for the start and the end of the i-th period of work.

Output

Output the answer to the problem.

Sample test(s)

input

1 3 2 1 5 10
0 10

output

30

input

2 8 4 2 5 10
20 30
50 100

output

570

  

 题意:电脑有三种模式,正常模式每分钟耗电p1,如果没有使用电脑t1分钟后变成第二种模式每分钟耗电p2,如果还是没有使用电脑t2分钟后变成第三种模式每分钟耗电p3。给定n个区间,每一个区间是正常模式,每个区间的间隔是没有使用,问总的耗电是多少

 思路:直接暴力枚举

 代码:

# input
list = raw_input().split()
n,p1,p2,t1,t2,t3 = map(int , list)

# solve
ans = 0
pre = -1

while n > 0:
    n -= 1
    list = raw_input().split()
    start,end = map(int , list)
    ans += (end-start)*p1

    if pre != -1:
       x = start-pre
       if x > t1:
          ans += t1*p1
          x -= t1
          if x > t2:
             ans += t2*p2
             x -= t2
             ans += x*p3
          else:
             ans += x*p2
       else:
          ans += x*p1
    pre = end

print ans

 第二题 11A

A. Increasing Sequence

time limit per test
1 second

memory limit per test
64 megabytes

input
standard input

output
standard output

A sequence a0, a1, ..., at - 1 is
called increasing if ai - 1 < ai for
each i: 0 < i < t.

You are given a sequence b0, b1, ..., bn - 1 and
a positive integer d. In each move you may choose one element of the given sequence and add d to
it. What is the least number of moves required to make the given sequence increasing?

Input

The first line of the input contains two integer numbers n and d (2 ≤ n ≤ 2000, 1 ≤ d ≤ 106).
The second line contains space separated sequence b0, b1, ..., bn - 1 (1 ≤ bi ≤ 106).

Output

Output the minimal number of moves needed to make the sequence increasing.

Sample test(s)

input

4 2
1 3 3 2

output

3

 

 题意:给定n个数的序列,现在要把这个序列变成递增的序列,满足ai < ai+1,现在规定每次可以选择一个数来增加d,问最少需要几次

 思路:枚举每一个数求个数即可

 代码:

# input
n,d = map(int , raw_input().split())
list = map(int , raw_input().split())

# getAns
ans = 0
for i in range(1,len(list)):
    if list[i] <= list[i-1]:
       x = (list[i-1]-list[i])/d+1
       list[i] += x*d
       ans += x
print ans
    

 第三题 12A

A. Super Agent

time limit per test
2 seconds

memory limit per test
256 megabytes

input
standard input

output
standard output

There is a very secret base in Potatoland where potato mash is made according to a special recipe. The neighbours from Porridgia decided to seize this recipe and to sell it to Pilauland. For this mission they have been preparing special agent Pearlo for many
years. When, finally, Pearlo learned all secrets of espionage, he penetrated into the Potatoland territory and reached the secret base.

Now he is standing at the entrance, but to get inside he need to pass combination lock. Minute ago one of the workers entered the password on the terminal and opened the door. The terminal is a square digital keyboard 3 × 3 with
digits from 1 to 9.

Pearlo knows that the password consists from distinct digits and is probably symmetric with respect to the central button of the terminal. He has heat sensor which allowed him to detect the digits which the worker pressed. Now he wants to check whether the
password entered by the worker is symmetric with respect to the central button of the terminal. This fact can Help Pearlo to reduce the number of different possible password combinations.

Input

Input contains the matrix of three rows of three symbols each. Symbol «X» means that the corresponding button was pressed, and «.»
means that is was not pressed. The matrix may contain no «X», also it may contain no «.».

Output

Print YES if the password is symmetric with respect to the central button of the terminal and NO otherwise.

Sample test(s)

input

XX.
...
.XX

output

YES

input

X.X
X..
...

output

NO

Note

If you are not familiar with the term «central symmetry», you may look into http://en.wikipedia.org/wiki/Central_symmetry

 题意:给定一个3*3的矩形,每个元素不是X就是.,问这个矩形是否是对称的

 思路:暴力枚举每一个点,然后判断每个点是否和它的对称点都相等即可

 代码:

# input
matrix = []
for i in range(3):
    matrix.append(raw_input())
# solve
def isOk():
    for i in range(3):
        for j in range(3):
            x = 2-i
            y = 2-j
            if matrix[i][j] != matrix[x][y]:
               return False
    return True
# ouput
if isOk():
    print "YES"
else:
    print "NO"
时间: 2024-09-20 00:16:52

Python解决codeforces ---- 4的相关文章

Python解决codeforces ---- 7

 第一题 20A A. BerOS file system time limit per test 2 seconds memory limit per test 64 megabytes input standard input output standard output The new operating system BerOS has a nice feature. It is possible to use any number of characters '/' as a deli

Python解决codeforces ---- 5

 第一题 13A A. Numbers time limit per test 1 second memory limit per test 64 megabytes input standard input output standard output Little Petya likes numbers a lot. He found that number 123 in base 16 consists of two digits: the first is 7 and the secon

Python解决codeforces ---- 2

 第一题 4A A. Watermelon time limit per test 1 second memory limit per test 64 megabytes input standard input output standard output One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in

Python解决codeforces ---- 6

 第一题 16A A. Flag time limit per test 2 seconds memory limit per test 64 megabytes input standard input output standard output According to a new ISO standard, a flag of every country should have a chequered field n × m, each square should be of one o

Python解决codeforces ---- 3

 第一题 7A A. Kalevitch and Chess time limit per test 2 seconds memory limit per test 64 megabytes input standard input output standard output A famous Berland's painter Kalevitch likes to shock the public. One of his last obsessions is chess. For more

Python解决codeforces ---- 1

 第一题 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 o

应用Python解决一些实际问题

Python 是一种简洁优美的脚本语言,它的诸多优点使它在完成某些任务时轻松自如.本文通过几个具体的例子阐明了这一点. 关于Python Python 是一种简洁优美的编程语言,它具有面向对象的特征,较好的粘合其他语言的能力及跨平台性.然而我认为同样重要的是, 它简单易学,书写代码简洁快速.此外,Python 提供了较多的模快,包含了相当多的功能,所以只要有一个可行的想法,那么用 Python 解决起来会是比较容易的.下面几个例子都源于我遇到的一些实际问题.借助于 Python,这些问题的解决都

python解决Fedora解压zip时中文乱码的方法_python

前言 很多时候在windows下压缩文件没问题,但是到了Linux下,出现乱码,很常见.以前在Ubuntu下,用`unzip -O GBK filename.zip` 就可以搞定. 换了Fedora后,暂时没发现乱码的压缩文件.晚上下载一本书的光盘,又碰到了乱码.尝试之前的方法没成功.看了下unzip的help,没-O那个参数了== 刚好找到一个用python解决的办法,分享下. 新建一个`.py`后缀的文件,直接复制粘贴代码: #!/usr/bin/env python # -*- codin

用python解决project euler中的题目

寒假期间学习了python,现在基本上就能上手使用它来解决project euler里面的题目了,用python真的是没得说的,一个字"赞".在C++中需要用一大堆代码实现的算法,在python中,只需要那么短短几行.而且还有惊艳的运行速度.借用<可爱的python>里面的一句话:"人生苦短,我用python". [project euler 055] 求经过一系列规则不能得到回文数的数的个数.题目在此: If we take 47, reverse a