D - Pyramid of Glasses cf676B

D - Pyramid of Glasses

Time Limit: 2000/1000 MS (Java/Others)      Memory Limit: 128000/64000 KB (Java/Others)

Submit Status

Problem Description

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

Each case 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.

Sample Input

3 5
4 8

Sample Output

4
6

Hint

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.

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 typedef long long LL;
 4 const int N=1e5+10;
 5 const int INF=0x3f3f3f3f;
 6 const double eps=1-1e-5;
 7 int cas=1,T;
 8 double dp[110][110];
 9 int main()
10 {
11     //freopen("1.in","w",stdout);
12 //    freopen("1.in","r",stdin);
13 //    freopen("1.out","w",stdout);
14     //scanf("%d",&T);
15     int n,t;
16     while(scanf("%d%d",&n,&t)==2)
17     {
18         memset(dp,0,sizeof(dp));
19         int ans=0;
20         memset(dp,0,sizeof(dp));
21         dp[1][1]=t;
22         if(t)
23         {
24             ans=1;
25             dp[1][1]-=1;
26             for(int i=1;i<n;i++)
27             {
28                 double x=0.5;
29                 for(int j=1;j<=i;j++)
30                 {
31                     dp[i+1][j]+=x*dp[i][j];
32                     dp[i+1][j+1]+=x*dp[i][j];
33                 }
34                 for(int j=1;j<=i+1;j++)
35                 {
36                     if(dp[i+1][j]>eps) dp[i+1][j]-=1,ans++;
37                     else dp[i+1][j]=0;
38                 }
39             }
40         }
41         printf("%d\n",ans);
42     }
43     //printf("time=%.3lf\n",(double)clock()/CLOCKS_PER_SEC);
44     return 0;
45 }

solve.cpp

题解:

直接把全部倒到最上面的杯子,然后模拟往下流,每个杯子满了之后就平均地把溢出的往两边流

时间: 2024-10-10 10:53:01

D - Pyramid of Glasses cf676B的相关文章

[CF-676B]PYRAMID OF GLASSES

题目链接:http://codeforces.com/problemset/problem/676/B 很水的递推: 题目大意: 有一个n层的酒杯金字塔,每个酒杯容量为1.每秒钟,会有1份酒倒到最上方的酒杯里.当某个酒杯装满时,它会以同样的流量溢出到下一层的两个酒杯之中.求t秒过后有多少装满的酒杯. 可以假设第一层有容积为T的酒,对于每一个酒杯来说来说,如果now>=1,下一层的左右两边就分别 += (now-1)/2: 上代码 1 #include<cstdio> 2 #include

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

原题请戳这里 题意: 将杯子摆成杨辉三角状,即顶层1个杯子,第二层2个杯子,……第N层N个杯子. 每一秒能倒满1个杯子,每次一个杯子满了,酒会平分得流入它下面支撑它的两个杯子中. 如下图所示.1 ≤ n ≤ 10, 0 ≤ t ≤ 10 000. 分析:由于n很小,所以直接模拟此过程,其实也是一个递推的过程. 注意,如果递推的时候没有递推到n+1层,那么最后统计的时候是统计>=1的个数而不是==1的个数, 因为当酒能倒满的杯子大于n层杯子即n*(n+1)/2<t时,递推过程终止于n层,不能向下

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

/* 队友告知的题意,大概是 杯子如题摆放,有 n 层 .最上面那个杯子一秒钟可以装满, 给出 n 和时间 t ,问 t 秒后可以装满多少个杯子. 大致思路是 使用二维数组模拟杯子往下漏水的过程. 最后扫一遍数组计算容量大于 1 的个数 . */ #include<cstdio> #include<cstring> #include<algorithm> #include<iostream> #include<string> using name

Codeforces Round #354 (Div. 2) ABCD

Codeforces Round #354 (Div. 2) Problems # Name     A Nicholas and Permutation standard input/output 1 s, 256 MB    x3384 B Pyramid of Glasses standard input/output 1 s, 256 MB    x1462 C Vasya and String standard input/output 1 s, 256 MB    x1393 D T

16.05.25-16.06.10 题集

继2016.05.24续: codeforces 651B. Beautiful Paintings-简单 http://codeforces.com/problemset/problem/651/B 大意:给出一个序列,求解其任意排列中满足ai?+?1?>?ai 的元素个数最大和. 分析:理想情况下,无重复元素的0从小到大的排列,满足条件的元素个数最多,是n-1. 非理想情况下还有重复元素,只要不断提取出重复的这些元素归到另一集合再这样讨论即可. #include <iostream>

Spatial pyramid pooling (SPP)-net (空间金字塔池化)笔记(转)

在学习r-cnn系列时,一直看到SPP-net的身影,许多有疑问的地方在这篇论文里找到了答案. 论文:Spatial Pyramid Pooling in Deep Convolutional Networks for Visual Recognition 转自:http://blog.csdn.net/xzzppp/article/details/51377731 另可参考:http://zhangliliang.com/2014/09/13/paper-note-sppnet/ http:/

hdu 5432 Pyramid Split(二分搜索)

Problem Description Xiao Ming is a citizen who's good at playing,he has lot's of gold cones which have square undersides,let's call them pyramids. Anyone of them can be defined by the square's length and the height,called them width and height. To ea

BNUOJ33568 Glass Pyramid(DFS)

Glass Pyramid Time Limit: 1000ms Memory Limit: 65536KB This problem will be judged on Ural. Original ID: 1968 64-bit integer IO format: %lld      Java class name: (Any) Prev Submit Status Statistics Discuss Next Font Size: +   - Type:   None  Graph T

Linear Spatial Pyramid Matching Using Sparse Coding for Image Classification

引入 Recently SVMs using spatial pyramid matching (SPM) kernel have been highly successful in image classification. Despite its popularity, these nonlinear SVMs have a complexity in training and O(n) in testing, where n is the training size, implying t