Pyramid of Glasses
来源:互联网 发布:有好看衣服的淘宝店铺 编辑:程序博客网 时间:2024/05/20 06:53
昨天的最后一题,感觉也没有多大的难度……可就是没有敲出来……见题:
E - Pyramid of Glasses
Description
Mary has just graduated from one well-known University and is now attending celebration party. Students like to dream of a beautiful life, so they used champagne glasses to construct a small pyramid. The height of the pyramid is n. The top level consists of only 1 glass, that stands on 2 glasses on the second level (counting from the top), then 3 glasses on the third level and so on.The bottom level consists of n glasses.
Vlad has seen in the movies many times how the champagne beautifully flows from top levels to bottom ones, filling all the glasses simultaneously. So he took a bottle and started to pour it in the glass located at the top of the pyramid.
Each second, Vlad pours to the top glass the amount of champagne equal to the size of exactly one glass. If the glass is already full, but there is some champagne flowing in it, then it pours over the edge of the glass and is equally distributed over two glasses standing under. If the overflowed glass is at the bottom level, then the champagne pours on the table. For the purpose of this problem we consider that champagne is distributed among pyramid glasses immediately. Vlad is interested in the number of completely full glasses if he stops pouring champagne in t seconds.
Pictures below illustrate the pyramid consisting of three levels.
Input
The only line of the input contains two integers n and t (1 ≤ n ≤ 10, 0 ≤ t ≤ 10 000) — the height of the pyramid and the number of seconds Vlad will be pouring champagne from the bottle.
Output
Print the single integer — the number of completely full glasses after t seconds.
Sample Input
3 5
4
4 8
6
该题通过画图可以很容易地看出dp方程,若dp[i-1][j-1]大于0 或者 dp[i-1][j]-1) 大于0 dp[i][j]+=(dp[i-1][j-1]-1)/2; dp[i][j]+=(dp[i-1][j]-1)/2。可以将倒了t秒的酒当作总的流量,用dp数组表示流经酒杯的总的流量,若流量大于等于1的话,则酒杯肯定能够倒满。这么理解不难写出代码:
//该题 构建dp 方程 若dp[i-1][j-1]大于0 或者 dp[i-1][j]-1) 大于0 dp[i][j]+=(dp[i-1][j-1]-1)/2; dp[i][j]+=(dp[i-1][j]-1)/2;//n秒 即总共倒了n杯的水 连起来 自顶到底地分散开去#include <cstdio>using namespace std;double dp[15][15];int main(){int n,t,ans=1;scanf("%d%d",&n,&t);dp[1][1]=t;for (int i=2; i<=n; i++)for (int j=1; j<=i; j++){if (dp[i-1][j-1]>1) //如果上左杯中大于一dp[i][j]+=(dp[i-1][j-1]-1)/2;if (dp[i-1][j]>1) //如果上面杯中大于一dp[i][j]+=(dp[i-1][j]-1)/2;if (dp[i][j]>=1) ans++; //分流的同时进行计数判断}//打印dp数组理解/*for(int i=1; i<=n; i++){for(int j=1; j<=i; j++)printf("%lf ",dp[i][j]);printf("\n");}*/printf("%d\n",t==0?0:ans);}总结:碰到这类题目还是不要去盲目笔算找规律,浪费时间且运算量大很容易影响心态。尽量往算法有关联上去靠,盲目运算得不偿失,失去了计算机运算的优势。还是见识太浅,还是得加油。
特记下,以备后日回顾。
- B. Pyramid of Glasses
- E - Pyramid of Glasses
- Pyramid of Glasses
- Pyramid of Glasses
- codeforces 676B Pyramid of Glasses 递归
- 【CodeForces 676】B - Pyramid of Glasses
- codeforce 676b Pyramid of Glasses
- Codeforces Round #354 (Div. 2)676B. Pyramid of Glasses
- codeforces 676B Pyramid of Glasses(模拟题)
- Codeforces Round #354 (Div. 2)-Pyramid of Glasses
- Codeforces 354 B Pyramid of Glasses (dp)
- Codeforces Round #354 (Div. 2) Pyramid of Glasses
- CodeForces 676B Pyramid of Glasses(举杯斟酒)
- CodeForces 676 B. Pyramid of Glasses(模拟)
- Pyramid of Glasses 酒杯金字塔 [CF-676B]
- Codeforces Round #354 (Div. 2) B Pyramid of Glasses(模拟)
- Codeforces Round #354 (Div. 2)B.Pyramid of Glasses(思维题)
- CodeForces 676B Pyramid of Glasses【杨辉三角倒鸡尾酒】
- 阻塞
- J2EE自定义标签
- PlSql链接不上Oracle问题跟踪
- Android逆向之旅--运行时修改内存中的Dalvik指令来改变代码逻辑
- startActivityForResult全解析
- Pyramid of Glasses
- string 类
- Activity
- stl string常用函数
- 关于Kendo ui 的简单介绍
- eclipse下执行mapreduce的配置和join
- java实现人民币数字转换中文大写的工具实例代码demo分享
- C# 实现是否设置指定程序为开机启动程序
- Linux中yum和apt-get用法及区别