Codeforces Round #354 (Div. 2)B.Pyramid of Glasses(思维题)

原创 2016年05月30日 14:57:52

题目链接:http://codeforces.com/contest/676/problem/B


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

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秒钟会有几个杯子满了。

大致思路:不用想太复杂,倒的酒的数量是一定的,所以从最上面开始推,下面酒的数量跟上面酒流出来的数量是一样的,然后一杯酒流出来的数量会分成两部分,这也就有点像杨辉三角,下面的杯子是上面两个杯子流出来数量和的一半


直接看代码吧:

#include <bits/stdc++.h>
using namespace std;
double temp[200][200];
int main()
{
    int n,t;
    while (~scanf("%d%d",&n,&t))
    {
        int res = 0;
        memset(temp,0,sizeof(temp));
        for (int i = 0 ; i < n ; i++ )
        {
            for (int j = 0 ; j <= i ; j++ )
            {
                if (i == 0)
                {
                    temp[i][j] = t * 1.0;
                    if(temp[i][j] >= 1.0)  //最上层的杯子,如果大于等于1 那么就说明杯子满了
                    {
                        res++;
                    }

                }
                else 
                {
                    if (j == 0)
                    {
                        if(temp[i-1][j] >= 1)  //判断上面的杯子有没有溢出
                            temp[i][j] = (temp[i - 1][j] - 1) * 1.0/ 2;
                        if (temp[i][j] >= 1.0)
                        {
                            res ++;
                        }
                    }
                    else 
                    {
                        if(j  <= i - 1)
                        {
                            if (temp[i-1][j-1] >= 1 && temp[i-1][j] >= 1)   //因为这个杯子会接收到两个杯子溢出
                                temp[i][j] = (temp[i - 1][j-1] + temp[i-1][j] - 2) * 1.0 / 2;  //因为溢出会分成两个部分,所以除2
                            else if(temp[i-1][j-1] >= 1) 
                            {
                                temp[i][j] = (temp[i-1][j-1] - 1) / 2;
                            }
                            else 
                            {
                                temp[i][j] = (temp[i-1][j] - 1) /2;
                            }
                            if(temp[i][j] >= 1.0)
                            {
                                res++;
                            }
                        }
                        else 
                        {
                            if (temp[i-1][j-1] >= 1)
                                temp[i][j] = (temp[i-1][j-1] - 1) * 1.0/ 2;
                            if(temp[i][j] >= 1.0)
                            {
                                res++;
                            }
                        }
                    }
                }
            }
        }
        printf("%d\n",res);
    }
    return 0;
}


版权声明:本文为博主原创文章,未经博主允许不得转载。

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

B. Pyramid of Glassestime limit per test 1 second memory limit per test 256 megabytes input sta...

【Codeforces Round 354 (Div 2)B】【简单模拟】Pyramid of Glasses 漏斗漏水n层t秒灌满多少个

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

Codeforces 354 B Pyramid of Glasses (dp)

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

codeforces 676B Pyramid of Glasses 递归

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

Codeforces Round #164 (Div. 2) C. Beautiful Sets of Points【思维题】

题意:给你一个n*m的矩形,问你在里面最多可以找多少个点(坐标为均为整数),使得之间的距离都并不是整数,输出点的数量和点的坐标(不唯一)。 分析:点之间的距离不是整数,就和容易想到对角线的形式,但输入...

Codeforces Round #354 (Div. 2) A Nicholas and Permutation(水题)

http://codeforces.com/problemset/problem/676/A A. Nicholas and Permutation time limit per ...

Codeforces Round #423 (Div. 2) B Black Square 黑色正方形 思维题

CF传送门 题意: 1. 给你由B和W组成的二维图 2. 要求把最少数量的W变成B使得图内所有的B形成一个正方形 3. 如果不能形成正方形就输出-1 题解: 1. 如果这张图全是W,那...

Codeforces Round #424 (Div. 2) B Keyboard Layouts 思维题 字符串处理

CF传送门 题意: 1. 这个世界上有很多种键盘,他们的共同点是排版一样,唯一不同就是字母的位置不同 2. 第一个字符串就是原键盘,第二个字符串是新键盘,第三个字符串是用原键盘进行读入的...

Codeforces Round #353 (Div. 2) B. Restoring Painting __ map or set 、思维题

自己画一个3*3的方格图, 然后标上 a, b, c, d 然后发现左上角标上x, 中间标上y,然后剩余3个空格可以表示出来。 故可以O(n)的来做 扫一遍,过程中用ans[][][][]来表示那个状...

Codeforces Round #366 (Div. 2) A 【水题】& B【博弈】 & C 【思维】

Codeforces Round #366 (Div. 2) A & B & C 【模拟】
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Codeforces Round #354 (Div. 2)B.Pyramid of Glasses(思维题)
举报原因:
原因补充:

(最多只允许输入30个字)