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 题解: 把连续的一段压缩成一个数,对新的数组求前缀和,用两个指针从左到右线性扫一遍. 一段值改变一部 ...
随机推荐
- [MySQL优化案例]系列 — 优化InnoDB表BLOB列的存储效率
首先,介绍下关于InnoDB引擎存储格式的几个要点:1.InnoDB可以选择使用共享表空间或者是独立表空间方式,建议使用独立表空间,便于管理.维护.启用 innodb_file_per_table 选 ...
- jenkins 入门教程(上)【转】
转自:https://www.cnblogs.com/yjmyzz/p/jenkins-tutorial-part-1.html jenkins是一个广泛用于持续构建的可视化web工具,持续构建说得更 ...
- C#连接MySQL 操作步骤
1.工具安装: 安装 MySQL For Windows,这个不多说,上官网下载: 安装mysql-connector-net,这个是MySQL数据库.NET开发驱动,因为C#是.NET架构的,所以需 ...
- 01 Getting Started 开始
Getting Started 开始 Install the Go tools Test your installation Uninstalling Go Getting help Downlo ...
- PHP获得用户的真实IP地址
<?php /** * 获得用户的真实IP地址 * * @access public * @return string */ function real_ip() { static $reali ...
- git忽略特殊文件或文件夹
1.在项目目录中添加“.gitignore”文件,项目目录就是你存放git工程的目录就是有“.git”目录的目录 vi .gitignore 2.在文件中添加如下内容,其中“/runtime/”是忽略 ...
- Unix IPC之Posix消息队列(3)
struct mq_attr { long mq_flags; /* message queue flag : 0, O_NONBLOCK */ long mq_maxmsg; /* max numb ...
- 用django-cors-headers做跨域
什么是CORS? CORS(跨域资源共享,Cross-Origin Resource Sharing)是一种跨域访问的机制,可以让Ajax实现跨域访问. 其实,在服务器的response header ...
- 【剑指Offer面试题】 九度OJ1389:变态跳楼梯
转自:http://www.myexception.cn/program/1973966.html 时间限制:1 秒内存限制:32 兆特殊判题:否提交:2331解决:1332 题目描述: 一只青蛙一次 ...
- Datagridview 中的checkbox 选中或勾选状态失效
1.问题描述,先选中第一行,再取消选择,然后点击部门全选,第一行没有打钩,状态是不选中的状态. 2.分析代码 先选中第一行,单元格的单击事件中 改变选中状态为1,第一行取消选择,单元格的单击事件中 改 ...