Google APAC test 2015 Round B Problem B - New Years Eve
来源:互联网 发布:爱思苹果助手 mac 编辑:程序博客网 时间:2024/05/18 02:49
源题链接:
https://code.google.com/codejam/contest/4214486/dashboard#s=p1
题意:
年会上的有一座由酒杯一层一层叠起来的酒杯塔:每一层的酒杯编号如下:
Level 1: 1Level 2: 1 2 3Level 3: 1 2 34 5 6Level 4: 1 2 3 4 5 67 8 9 10每一个非最底层的酒杯脚下有三个杯子支撑它。现在用B瓶750ml的酒从第一层那个酒杯开始注酒,当一个酒杯的酒满时,则溢出的酒平均溢到它脚下的三个酒杯。
比如第2层的编号为2的酒杯(250ml)酒满后,多余的酒就平均地溢出到第3层的2,4,5号酒杯。求B瓶酒倒完后第L层的第N个酒杯里有多少酒?
分析:
模拟酒一层一层往下溢出的方法,计算出每一层的每个酒杯里会流过多少酒(包括溢出的的和最后剩余在酒杯里的)
用二位数组left[][]记录第i层的每个杯子里流过的酒量,然后根据它生成第i+1层的对应的left[][](用tmp[][]暂存),递推关系如下:
tmp[j][k] = tmp[j][k] + max(float(left[j][k]-250)/3, 0)
tmp[j+1][k] = tmp[j+1][k] + max(float(left[j][k]-250)/3, 0)
tmp[j+1][k+1] = tmp[j+1][k+1] + max(float(left[j][k]-250)/3, 0)
代码:
from math import *
from bisect import *
def wine(B, L, N):
num = B*3
sum = 0
left = [ [750*B] ]
bis = [0]
for i in range(1, L):
tmp = [ [ 0 for ii in range(0, i+1)] for jj in range(0, i+1) ]
for j in range(0, i):
for k in range(0, j+1):
tmp[j][k] = tmp[j][k] + max(float(left[j][k]-250)/3, 0)
tmp[j+1][k] = tmp[j+1][k] + max(float(left[j][k]-250)/3, 0)
tmp[j+1][k+1] = tmp[j+1][k+1] + max(float(left[j][k]-250)/3, 0)
left = tmp
bis.append(i*(i+1)/2)
addr = bisect(bis, N-1)
return min(left[addr-1][N-1-(addr*(addr-1))/2], 250)
fin = open('b_large.in','r')
fout = open('b_large.out','w')
line = fin.readline()
n = int(line)
for i in range(0,n):
line = fin.readline()
line = line.split(' ')
B = int(line[0])
L = int(line[1])
N = int(line[2])
res = wine(B,L,N)
fout.write("Case #%d: %.7f\n"%(i+1, res))
fin.close()
fout.close()
- Google APAC test 2015 Round B Problem B - New Years Eve
- google APAC round 2 problem B New Years Eve 倒酒问题
- Google APAC test 2015 Round B Problem A - Password Attacker
- Google APAC test 2015 Round B Problem C - Card Game
- Google APAC test 2015 Round B Problem D-Parentheses Order
- Problem B. gWheels Google APAC 2016 University Test Round B
- Problem B. Rain Google APAC 2017 University Test Round A
- Problem B. gFiles Google APAC 2016 University Test Round C
- Problem B. gBalloon Google APAC 2016 University Test Round D
- Problem A. Travel Google APAC 2016 University Test Round B
- Problem C. gNumbers Google APAC 2016 University Test Round B
- Problem B. gCube Google APAC 2016 University Test Round A
- Google中国2015校园招聘笔试Round D APAC Test Problem B. GBus count
- Google APAC 2017 University Test Round B
- [Google APAC 2015]Round A.Problem B.Super 2048
- Problem B. Sherlock and Watson Gym Secrets Google APAC 2017 University Test Round B
- Google China New Grad Test 2014 Round A Problem B
- Problem C. Watson and Intervals Google APAC 2017 University Test Round B
- 最少硬币问题(多重背包问题)
- GDB 调试多进程
- 一个默默走在安卓路上的菜鸟
- zoj 1188 - DNA Sorting
- GDB调试多线程
- Google APAC test 2015 Round B Problem B - New Years Eve
- cocos2d-x 3.2居然不能繁体中文设置?改引擎吧
- 大数据不仅仅是Hadoop
- ios图片要求
- Jmeter系列(一)-录制测试脚本
- CentOS安装MySQL时报Curses library not found异常
- DialogFragment示例
- Android组件之Activity生命周期解析
- C#中this的作用是什么