Codeforces Round #354 (Div. 2) B. Pyramid of Glasses (analog + thinking)

Source: Internet
Author: User
Tags cmath

The original question, please poke here

Test instructions

Put the cup into a Yang Hui triangle, that is, the top 1 cups, the second Layer 2 cups, ... Nth Layer N Cups.

Every second can fill 1 cups, each time a cup is full, the cocktail party is divided into the bottom of it to support its two cups.

As shown in. 1 ≤ n ≤ 10, 0≤ t ≤10 000.

Analysis: Because n is small, it is a recursive process to directly simulate this process.

Note that if recursion is not recursive to the n+1 layer, then the last statistic is the number of statistics >=1 rather than the number of ==1,

Because when the wine can fill the cup larger than the N-Layer Cup (n+1)/2<t, the recursive process terminates on the N-level and cannot be pushed down. So the bottom

A layer of wine is greater than 1. The code is as follows:

#include <cstdio>#include<map>#include<algorithm>#include<iostream>#include<Set>#include<cmath>#include<cstring>using namespaceStd;typedefLong Longll;Doublep[ A][ A];intMain () {intn,t;  while(~SCANF ("%d%d",&n,&t) {memset (P,0,sizeof(p));  for(intI=1; i<=t;i++) {p[1][1]+=1;  for(intj=1; j<n;j++)            {                 for(intk=1; k<=j;k++)                {                    //cout<<j<< ' <<k<<endl;                    if(p[j][k]>1) {p[j+1][k] + = (p[j][k]-1)/2; P[j+1][k+1] + = (p[j][k]-1)/2; P[J][K]=1; //cout<<i<<endl; //cout<<j+1<< ' <<k<< ' <<p[j+1][k]<<endl; //cout<<j+1<< ' <<k+1<< ' <<p[j+1][k+1]<<endl;                    }                }            }        }        intCNT =0;  for(intj=1; j<=n;j++)        {             for(intk=1; k<=j;k++)            {                if(p[j][k]>=1) CNT++; }} cout<<cnt<<Endl; }    return 0;}
View Code

If you push to the n+1 layer, the number of ==1 is counted.

#include <cstdio>#include<map>#include<algorithm>#include<iostream>#include<Set>#include<cmath>#include<cstring>using namespaceStd;typedefLong Longll;Doublep[ A][ A];intMain () {intn,t;  while(~SCANF ("%d%d",&n,&t) {memset (P,0,sizeof(p));  for(intI=1; i<=t;i++) {p[1][1]+=1;  for(intj=1; j<=n;j++)//<=n guaranteed recursion to n+1 layer            {                 for(intk=1; k<=j;k++)                {                    if(p[j][k]>1) {p[j+1][k] + = (p[j][k]-1)/2; P[j+1][k+1] + = (p[j][k]-1)/2; P[J][K]=1; }                }            }        }        intCNT =0;  for(intj=1; j<=n;j++)        {             for(intk=1; k<=j;k++)            {                if(p[j][k]==1)//cnt++; }} cout<<cnt<<Endl; }    return 0;}

Codeforces Round #354 (Div. 2) B. Pyramid of Glasses (analog + thinking)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.