原题链接

B. Pyramid of Glasses

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.

Examples

Input

3 5

Output

4

Input

4 8

Output

6

Note

In the first sample, the glasses full after 5 seconds are: the top glass, both glasses on the second level and the middle glass at the bottom level. Left and right glasses of the bottom level will be half-empty.

大致题意

有n层高的杯子,每秒钟从顶部倒一杯水下来,问经过t秒,有多少个杯子的水满了。

思路

很有趣的模拟题。首先考虑把每个杯子看成‘1’,然后将每个杯子写进double类型的二维数组中,如果杯子满了,则将溢出的分成相等的两份然后分别流进下层对应的两个杯子中,同时对满了的杯子计数。

AC代码

#include<iostream>
using namespace std;
double v[15][15];
void pour(int n)
{
    v[1][1]+=1;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=i;j++)
        {
            if(v[i][j]<=1) continue;
            double p=v[i][j]-1;
            v[i][j]=1;
            v[i+1][j]+=p/2;
            v[i+1][j+1]+=p/2;
        }
}
int main(void)
{
    int n,t;
    cin>>n>>t;
    for(int i=1;i<=t;i++)
        pour(n);
    int full=0;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=i;j++)
        {
            if(v[i][j]>0.9999)
            full++;
        }
    cout<<full<<endl;
    return 0;
}

如有疑问欢迎私信!!

B. Pyramid of Glasses的更多相关文章

  1. CF 676B Pyramid of Glasses[模拟]

    B. Pyramid of Glasses time limit per test 1 second memory limit per test 256 megabytes input standar ...

  2. codeforces 676B B. Pyramid of Glasses(模拟)

    题目链接: B. Pyramid of Glasses time limit per test 1 second memory limit per test 256 megabytes input s ...

  3. Pyramid of Glasses(递推)

    Pyramid of Glasses time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  4. Codeforces Round #354 (Div. 2) B. Pyramid of Glasses 模拟

    B. Pyramid of Glasses 题目连接: http://www.codeforces.com/contest/676/problem/B Description Mary has jus ...

  5. [Codeforces676B]Pyramid of Glasses(递推,DP)

    题目链接:http://codeforces.com/problemset/problem/676/B 递推,dp(i, j)表示第i层第j个杯子,从第一层开始向下倒,和数塔一样的题.每个杯子1个时间 ...

  6. 【CF 676B Pyramid of Glasses】模拟,递归

    题目链接:http://codeforces.com/problemset/problem/676/B 题意:一个n层的平面酒杯金字塔,如图,每个杯子的容量相同.现在往最顶部的一个杯子倒 t 杯酒,求 ...

  7. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  8. Codeforces Round #354 (Div. 2)

    贪心 A Nicholas and Permutation #include <bits/stdc++.h> typedef long long ll; const int N = 1e5 ...

  9. Codeforces Round #354 (Div. 2)-B

    B. Pyramid of Glasses 题目链接:http://codeforces.com/contest/676/problem/B Mary has just graduated from ...

随机推荐

  1. linux_inode和block

    linux里一切皆文件 什么是文件属性? 文件本身带有的信息, 包括:索引节点编号. 文件类型以及权限.硬链接个数(备份作用).所有者.所属组.文件大小.修改月.修改日.时分 151387 -rw-- ...

  2. <script>元素在XHTML中的用法

    编写XHTML代码的规则要比编写HTML严格得多,例如如下代码: <script type="text/javascript"> function compare(a, ...

  3. aliyun 购买的linux安装tomcat

    按照网上的教程,下载tomcat,解压(即安装),启动,发现无法访问.有说端口未开放,修改/etc/sysconfig/iptables,添加端口开放.未发现有此文件,只有iptables-confg ...

  4. 国内不谈java

    今天晚上在整理电脑,不知道怎么回事,电脑里面放着一篇文章.打开一看写的挺好的,现在就贴出来,望共勉.   国内不谈java--会有千万人跳出来和你争嘴的.越是如此,我越是不忍心不说出来,越是不不忍心看 ...

  5. Python-常用第三方库

    python常用框架及第三方库(转载) 一.Web框架 1.Django: 开源web开发框架,它鼓励快速开发,并遵循MVC设计,比较庞大,开发周期短.Django的文档最完善.市场占有率最高.招聘职 ...

  6. Shell跳板机sshstack

    笔者Q:972581034 交流群:605799367.有任何疑问可与笔者或加群交流 源码地址: https://github.com/sshstack/sshstack 为什么要写shell跳板机? ...

  7. 从iconfont下载项目所需的图标资源

    前端开发中,经常会用到各种各样的图标(icon).这些icon,如果每个都要自己去做,那真的是耗时又耗力.但是,有了阿里巴巴矢量图标库这样的平台后,一切都变得简单了起来. 本文以此平台为例,演示如何搜 ...

  8. 使用localhost可以访问,但使用本地ip+端口号无法访问

    今天想使用ip访问本机的iview-admin项目,结果怎么配置都无法访问,根据iview工程执行的命令npm run dev了解到是webpack配置的问题,打开工程里的node_modules文件 ...

  9. python字符串常用的方法解析

    这是本人在学习python过程中总结的一些关于字符串的常用的方法. 文中引用了python3.5版本内置的帮助文档,大致进行翻译,并添加了几个小实验. isalnum S.isalnum() -> ...

  10. 安装与配置cacti 0.8.8b

    cacti安装与配置 一.安装所需要的软件 Apache    安装Apache文档 Mysql      安装Mysql文档 Php       安装PHP文档 Rrdtool    安装rrdto ...