原题链接

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. BSA Network Shell系列-redi命令

    redi ## 1 功能概述 redi将输出重定向到一个文件中 ## 2 语法 redi [-?] [-a] filename ## 3 使用示例 1 将输出重定向到隐式路径所在主机的/tmp/hah ...

  2. CentOS如何把deb转为rpm

    说明:可以转换,但不一定可用,可以根据报错提示,安装需要的依赖. 1 安装alien工具,下载地址http://ftp.de.debian.org/debian/pool/main/a/alien/ ...

  3. Halcon一日一练:Halcon异常判断方法

    1.TryCatch tryCatch处理的方式如下: try *可能会出现错误的语句 .... catch(Exception) *获取错误代码 ErrorCode:=Exception[] **对 ...

  4. 合理使用软引用和弱引用,提升JVM内存使用性能

    在项目运行时,OOM异常是比较处理的,因为从日志看出的发生异常的代码点可能仅仅是最后一根稻草,从中可能未必能发现OOM的原因,而且OOM未必是固定重现的. 上医治未病,与其等OOM问题发生时再通过看日 ...

  5. linux命令读取文件中特定行

    1.如果你只想看文件的前5行,可以使用head命令, 如: head -5 /etc/passwd 2.如果你想查看文件的后10行,可以使用tail命令, 如: tail -10 /etc/passw ...

  6. jenkins持续集成简介[一]

    标签(linux): jenkins 笔者Q:972581034 交流群:605799367.有任何疑问可与笔者或加群交流 什么时持续集成? Continuous integration(CI) 持续 ...

  7. 【转】matlab针对不同格式文件的读写

    本技术支持指南主要处理:ASCII, binary, and MAT files.要得到MATLAB中可用来读写各种文件格式的完全函数列表,可以键入以下命令: help iofun MATLAB中有两 ...

  8. Sql Server的艺术(二) SQL复杂条件搜索

    本次讲到where字句中经常用到的集中较为复杂的搜索条件,包括组合的查询条件.IN运算符.NOT运算符.LIKE运算符和相关通配符. 学习本节需要用到一下两张表: CREATE TABLE TEACH ...

  9. redis基础知识

    特点 内存+磁盘的持久化保存 具有非常丰富的数据类型,尤其擅长数组类数据的高速度处理 数据快照 自带的主从复制 丰富的数据类型 字符串 链表 集合 有序集合 散列表 适用场景 时间线应用 得益于链表的 ...

  10. python各种运算优先级一览表

    ##python各种运算的优先级 运算符 描述 lambda Lambda表达式 or 布尔"或" and 布尔"与" not x 布尔"非" ...