原题链接

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代码

  1. #include<iostream>
  2. using namespace std;
  3. double v[15][15];
  4. void pour(int n)
  5. {
  6. v[1][1]+=1;
  7. for(int i=1;i<=n;i++)
  8. for(int j=1;j<=i;j++)
  9. {
  10. if(v[i][j]<=1) continue;
  11. double p=v[i][j]-1;
  12. v[i][j]=1;
  13. v[i+1][j]+=p/2;
  14. v[i+1][j+1]+=p/2;
  15. }
  16. }
  17. int main(void)
  18. {
  19. int n,t;
  20. cin>>n>>t;
  21. for(int i=1;i<=t;i++)
  22. pour(n);
  23. int full=0;
  24. for(int i=1;i<=n;i++)
  25. for(int j=1;j<=i;j++)
  26. {
  27. if(v[i][j]>0.9999)
  28. full++;
  29. }
  30. cout<<full<<endl;
  31. return 0;
  32. }

如有疑问欢迎私信!!

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. 控制器没有足够的带宽可利用为USB大容量存储设备的解决方法

    伴随网盘时代的没落,最近刚入手了一个移动硬盘.现在的移动硬盘都是USB3.0,传输速度比USB2.0要快很多.但是链接笔记本电脑后发现传输速度在20MB/s左右,跟USB2.0速度差不多,并不能达到传 ...

  2. ORACLE SQL脚本能否修改字段名称?

    在看到标题时,你先想想:在ORACLE中能否修改一个表的某个字段名呢?如果能的话,你是否还记得SQL脚本如何写的呢,呵呵,写这个的目的是因为在论坛上看见许多信誓旦旦的说ORACLE中不能修改字段名称, ...

  3. spring的jar各包作用

    http://yjwen337.blog.163.com/blog/static/3625847820106132949858/[转]spring.jar是包含有完整发布的单个jar 包,spring ...

  4. gd库的安装

    gd库简介 主要用途编辑 在网站上GD库通常用来生成缩略图,或者用来对图片加水印,或者用来生成汉字验证码,或者对网站数据生成报表等.在PHP处理图像,可使用GD库,而GD库开始时是支持GIF的,但由于 ...

  5. Core Animation 文档翻译 (第四篇)

    Core Animation 文档翻译(第四篇) 让Layer的content动画起来 核心动画的基础接口以及为拥有Layer的View做的动画扩展接口,使得为Layer制作复杂动画变得简单化.例如改 ...

  6. records.config文件参数解释

    # Process Records Config File # # <RECORD-TYPE> <NAME> <TYPE> <VALUE (till end ...

  7. easyui_datagrid 行内使用comobox的编码实现

    easyui datagrid组件的列属性中有一个editor属性,官方介绍如下: 所以,我们可以通过编码实现datagrid行内插入comobox的方式来实现某些场合的需要,具体编码实现如下: // ...

  8. spring boot 中实现兼容不同的请求类型的方法。

    比如一个接口,既想实现请求参数是application/json,又想实现form提交,改怎么做呢?用postman去测试,发现不可能做到两全其美. 我有一个方法,就是不用requestbody,也可 ...

  9. python小练习(自己瞎倒腾)

    python小练习 在网上无意中看到一个问题,心血来潮写了写,觉得比较有意思,以后遇到这种有意思的小练习也记录下. #!/usr/bin/env python # -*- coding:utf-8 - ...

  10. Getting the pixel coordinates of text or ticks in matplotlib

    The exact pixel coordinates of title, labels, legends or ticks are important information for the tra ...