设为首页 收藏本站
查看: 557|回复: 0

[经验分享] Python解决codeforces ---- 4

[复制链接]

尚未签到

发表于 2017-5-1 07:53:51 | 显示全部楼层 |阅读模式
  

  第一题 10A
  


A. Power Consumption Calculation

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output



[size=1em]
Tom is interested in power consumption of his favourite laptop. His laptop has three modes. In normal mode laptop consumesP1watt
per minute.T1minutes
after Tom moved the mouse or touched the keyboard for the last time, a screensaver starts and power consumption changes toP2watt
per minute. Finally, afterT2minutes
from the start of the screensaver, laptop switches to the "sleep" mode and consumesP3watt
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 intontime
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

[size=1em]
The first line contains 6 integer numbersn,P1,P2,P3,T1,T2(1 ≤ n ≤ 100, 0 ≤ P1, P2, P3 ≤ 100, 1 ≤ T1, T2 ≤ 60).
The followingnlines contain description of Tom's work. Eachi-th
of these lines contains two space-separated integersliandri(0 ≤ li < ri ≤ 1440,ri < li + 1fori < n),
which stand for the start and the end of thei-th period of work.



Output

[size=1em]
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



[size=1em]
A sequencea0, a1, ..., at - 1is
called increasing ifai - 1 < aifor
eachi: 0 < i < t.
[size=1em]
You are given a sequenceb0, b1, ..., bn - 1and
a positive integerd. In each move you may choose one element of the given sequence and adddto
it. What is the least number of moves required to make the given sequence increasing?



Input

[size=1em]
The first line of the input contains two integer numbersnandd(2 ≤ n ≤ 2000, 1 ≤ d ≤ 106).
The second line contains space separated sequenceb0, b1, ..., bn - 1(1 ≤ bi ≤ 106).



Output

[size=1em]
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 <= list[i-1]:
x = (list[i-1]-list)/d+1
list += 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



[size=1em]
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.
[size=1em]
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 keyboard3 × 3with
digits from1to9.
[size=1em]
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

[size=1em]
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

[size=1em]
PrintYESif the password is symmetric with respect to the central button of the terminal andNOotherwise.



Sample test(s)

input

XX.
...
.XX



output

YES



input

X.X
X..
...



output

NO







Note

[size=1em]
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[j] != matrix[x][y]:
return False
return True
# ouput
if isOk():
print "YES"
else:
print "NO"

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-371434-1-1.html 上篇帖子: Python解决codeforces ---- 6 下篇帖子: Python解决codeforces ---- 3
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表