Codeforces Round #354 (Div. 2) B. Pyramid of Glasses 模拟
B. Pyramid of Glasses
题目连接:
http://www.codeforces.com/contest/676/problem/B
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
Sample Output
4
Hint
题意
有n层的杯子,然后每秒钟都会倒一杯水
问你倒了t秒后,有几个杯子是满的
题解:
模拟模拟,用double直接模拟就好了……
其实很像数字数字三角形那道题诶
代码
#include<bits/stdc++.h>
using namespace std;
int n,t;
double a[15][15];
void pour()
{
a[1][1]+=1;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=i;j++)
{
if(a[i][j]<=1)continue;
double p = a[i][j]-1;
a[i][j]=1;
a[i+1][j]+=p/2;
a[i+1][j+1]+=p/2;
}
}
}
int main()
{
scanf("%d%d",&n,&t);
for(int i=1;i<=t;i++)
pour();
int ans = 0;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=i;j++)
{
if(a[i][j]>=0.9999)ans++;
}
}
cout<<ans<<endl;
}
Codeforces Round #354 (Div. 2) B. Pyramid of Glasses 模拟的更多相关文章
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #367 (Div. 2) B. Interesting drink (模拟)
Interesting drink 题目链接: http://codeforces.com/contest/706/problem/B Description Vasiliy likes to res ...
- Codeforces Round #354 (Div. 2)-B
B. Pyramid of Glasses 题目链接:http://codeforces.com/contest/676/problem/B Mary has just graduated from ...
- Codeforces Round #354 (Div. 2)
贪心 A Nicholas and Permutation #include <bits/stdc++.h> typedef long long ll; const int N = 1e5 ...
- Codeforces Round #354 (Div. 2)-D
D. Theseus and labyrinth 题目链接:http://codeforces.com/contest/676/problem/D Theseus has just arrived t ...
- Codeforces Round #354 (Div. 2)-C
C. Vasya and String 题目链接:http://codeforces.com/contest/676/problem/C High school student Vasya got a ...
- Codeforces Round #354 (Div. 2)-A
A. Nicholas and Permutation 题目链接:http://codeforces.com/contest/676/problem/A Nicholas has an array a ...
- Codeforces Round #354 (Div. 2) D. Theseus and labyrinth
题目链接: http://codeforces.com/contest/676/problem/D 题意: 如果两个相邻的格子都有对应朝向的门,则可以从一个格子到另一个格子,给你初始坐标xt,yt,终 ...
- Codeforces Round #354 (Div. 2) C. Vasya and String
题目链接: http://codeforces.com/contest/676/problem/C 题解: 把连续的一段压缩成一个数,对新的数组求前缀和,用两个指针从左到右线性扫一遍. 一段值改变一部 ...
随机推荐
- Resouce, platform_device 和 platform_driver 的关系【转】
转自:http://blog.csdn.net/uruita/article/details/7278313 從2.6版本開始引入了platform這個概念,在開發底層驅動程序時,首先要確認的就是設備 ...
- java基础62 JavaScript中的函数(网页知识)
1.JavaScript中,函数的格式 function 函数名(形参列表){ 函数体; } 2.JavaScript中,函数需要注意的细节 1.在javaScript中,函数定义形参时,是不能使用v ...
- HTML网页自动跳转
<meta http-equiv="refresh" content="3;URL=res.html">
- 多线程 or I/O复用select/epoll
1:多线程模型适用于处理短连接,且连接的打开关闭非常频繁的情形,但不适合处理长连接.线程模型默认情况下,在Linux下每个线程会开8M的栈空间,在TCP长连接的情况下,以2000/分钟的请求为例,几乎 ...
- java正则表达式(转)
1.验证email public static void main(String[] args) { // 要验证的字符串 String str = "service@xsoftlab.ne ...
- 批处理命令篇--配置免安装mysql
免安装版的mysql是进行软件绿色发布的绝佳助手,本文介绍一种使用批处理命令自动配置mysql的方法. (1)建立三个文件,分别是:service install.bat,temp.txt,updat ...
- hadoop 初探之第二篇(杂谈)
NameNode:名称节点,主要功能在于实现保存文件元数据,这些元数据直接保存在内存中,为了保证元数据的持久性,而也会周期性的同步到磁盘上去.磁盘上的数据通常被称为元数据的映像数据 image fil ...
- ueditor初始化
一.下载文件复制到项目中 二.复制表情文件 三.复制列表图片 四.修改ueditor.config.js文件 五.接着修改net文件下config.json文件 六.完蛋了,不支持IE8,版本替换为了 ...
- 基于Bootstrap的Asp.net Mvc 分页的实现
最近写了一个mvc 的 分页,样式是基于 bootstrap 的 ,提供查询条件,不过可以自己写样式根据个人的喜好,以此分享一下.首先新建一个Mvc 项目,既然是分页就需要一些数据,我这边是模拟了一些 ...
- mysql 函数group_concat()
本文通过实例介绍了MySQL中的group_concat函数的使用方法,比如select group_concat(name) .MySQL中group_concat函数完整的语法如下:group_c ...