原题链接

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. 国家语言,语言代码,locale id对应表

    国家语言,语言代码,locale id对应表.比如 en_US对应的id为1033, 中文的locale=zh_CN,id=2052. Locale Languagecode LCIDstring L ...

  2. java1.8--Null Object模式

    整理这篇博客是因为现在在整理java8中的optional,所以觉得很有必要整理下Null Object模式.java.lang.NullPointerException,只要敢自称Java程序员,那 ...

  3. Python 正则表达式 (python网络爬虫)

    昨天 2018 年 01 月 31 日,农历腊月十五日.20:00 左右,152 年一遇的月全食.血月.蓝月将今晚呈现空中,虽然没有看到蓝月亮,血月.月全食也是勉强可以了,还是可以想像一下一瓶蓝月亮洗 ...

  4. 企业级分布式存储应用与实战FastDFS实现

    FASTDFS是什么 FastDFS是由国人余庆所开发,其项目地址:https://github.com/happyfish100 FastDFS是一个轻量级的开源分布式文件系统,主要解决了大容量的文 ...

  5. Spring 4.x (三)

    1 Spring中加入DataSource并引入jdbc.properties 步骤: ①加入c3p0的jar包和mysql的驱动包 ②在src下新建jdbc.propertes文件 jdbc.dri ...

  6. PHP读取XML文件

    xml主键被json取代,大概了解一下就OK了 简要: 加载xml文件:$xml = simplexml_load_file('sa.xml');//$xml是一个对象 读取节点:echo $xml- ...

  7. lvs_nat

    nat模式环境模拟 1.实验环境概览 192.168.1.186 192.168.75.131 双网卡 dir 调度器(vip) ipvsadm,双网卡 192.168.1.185 单网卡 rs1 真 ...

  8. ASP.NET没有魔法——ASP.NET MVC 模型验证

    在前面的文章中介绍了用户的注册及登录功能,在注册用户时可以通过代码的形式限制用户名及密码的格式,如果不符合要求那么就无法完成操作,如下图: 该功能的原理是Identity基于的Entity Frame ...

  9. JSP自定义标签就是如此简单

    tags: JSP 为什么要用到简单标签? 上一篇博客中我已经讲解了传统标签,想要开发自定义标签,大多数情况下都要重写doStartTag(),doAfterBody()和doEndTag()方法,并 ...

  10. 00_Python面试题_迭代更新

    一.Python是什么类型的语言,以及和其他语言对比 1.Python是一种解释性语言,他和C语言以及C衍生的语言不通,在Python运行之前不需要编译,其他解释语言还有Ruby.PHP. 2.Pyt ...