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 namespace std;
int main()
{
    double a[15][15];
    int n,t;
    memset(a,0,sizeof(a));
    scanf("%d%d",&n,&t);
    a[1][1] = t;
    for(int i=2;i<=10;i++)
    {
        for(int j=1;j<=10;j++)
        {
            double x = ( a[i-1][j]>1 ? (a[i-1][j] - 1) : 0 )/2; // 如果不够 1 既没有装满就不能继续往下漏
            double y = ( a[i-1][j-1]>1 ? (a[i-1][j-1] - 1) : 0 )/2;
            a[i][j] += x+y;
        }
    }
    int ans = 0;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
            if(a[i][j]>=1) ans++;
    cout<<ans<<endl;
    return 0;
}
时间: 2024-08-20 17:20:17

Codeforces Round #354 (Div. 2) - B. Pyramid of Glasses的相关文章

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) 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

Codeforces Round #354 (Div. 2)

5/5 水了场CF,写个水水地题解~~ 题A CodeForces 676A 题意:给你一个排列,问你交换一次,最大最小位置最远是多少? 题解:暴力交换,暴力算,反正数据小.偷懒被hack更惨!! 1 /*zhen hao*/ 2 #include <bits/stdc++.h> 3 using namespace std; 4 5 #define lson l, m, rt*2 6 #define rson m + 1, r, rt*2+1 7 #define xx first 8 #def

Codeforces Round #354 (Div. 2) C. Vasya and String

题目大意:有一个(a|b)^N的由a和b构成的长度为N的字符串,允许修改其中k位.问能构成的最长的全为a或全为b的子串的长度最长为多少. 思路,用两个队列分别保存前K+1个a和b的位置,以i为结尾的最长的子串的长度就是i减去队列头元素的值. #include <iostream> #include <cstdio> #include <memory.h> #include <queue> using namespace std; int main(int a

Codeforces Round #354 (Div. 2) A

题目给出1~n的n个数的一个permutation,swap一次任意两个数,output 1 and n 之间的最大距离 记录1 and n的位置p,确定1的位置,移动n到位置1 and n,确定n的位置,移动1到位置1 and n,output max value. O(n). #include <cstdio> #include <cmath> #include <algorithm> using namespace std; int n; struct node{

Codeforces Round #279 (Div. 2) ABCD

Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name     A Team Olympiad standard input/output 1 s, 256 MB  x2377 B Queue standard input/output 2 s, 256 MB  x1250 C Hacking Cypher standard input/output 1 s, 256 MB  x740 D Chocolate standard input/

Codeforces Round #428 (Div. 2)

Codeforces Round #428 (Div. 2) A    看懂题目意思就知道做了 #include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define rep(i,a,b) for (int i=a; i<=b; ++i) #define per(i,b,a) for (int i=b; i>=a; --i

Codeforces Round #424 (Div. 2) D. Office Keys(dp)

题目链接:Codeforces Round #424 (Div. 2) D. Office Keys 题意: 在一条轴上有n个人,和m个钥匙,门在s位置. 现在每个人走单位距离需要单位时间. 每个钥匙只能被一个人拿. 求全部的人拿到钥匙并且走到门的最短时间. 题解: 显然没有交叉的情况,因为如果交叉的话可能不是最优解. 然后考虑dp[i][j]表示第i个人拿了第j把钥匙,然后 dp[i][j]=max(val(i,j),min(dp[i-1][i-1~j]))   val(i,j)表示第i个人拿

Codeforces Round #424 (Div. 2) C. Jury Marks(乱搞)

题目链接:Codeforces Round #424 (Div. 2) C. Jury Marks 题意: 给你一个有n个数序列,现在让你确定一个x,使得x通过挨着加这个序列的每一个数能出现所有给出的k个数. 问合法的x有多少个.题目保证这k个数完全不同. 题解: 显然,要将这n个数求一下前缀和,并且排一下序,这样,能出现的数就可以表示为x+a,x+b,x+c了. 这里 x+a,x+b,x+c是递增的.这里我把这个序列叫做A序列 然后对于给出的k个数,我们也排一下序,这里我把它叫做B序列,如果我