【HDU5524 BC61 div1 B】【SET模拟】Subtrees 二叉树不同子节点树的子树个数


Subtrees

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 102    Accepted Submission(s): 58


Problem Description
There is a complete binary tree with N nodes.The subtree of the node i has Ai nodes.How many distinct numbers are there of Ai?
 

Input
There are multiple test cases, no more than 1000 cases.
For each case contains a single integer N on a line. (1N1018)
 

Output
The output of each case will be a single integer on a line:the number of subtrees that contain different nodes.
 

Sample Input
 
       
5 6 7 8
 

Sample Output
 
       
3 4 3 5
 

Source
BestCoder Round #61 (div.2)
 

 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
void fre(){freopen("c://test//input.in","r",stdin);freopen("c://test//output.out","w",stdout);}
#define MS(x,y) memset(x,y,sizeof(x))
#define MC(x,y) memcpy(x,y,sizeof(x))
#define MP(x,y) make_pair(x,y)
#define ls o<<1
#define rs o<<1|1
typedef long long LL;
typedef unsigned long long UL;
typedef unsigned int UI;
template inline void gmax(T1 &a,T2 b){if(b>a)a=b;}
template inline void gmin(T1 &a,T2 b){if(bsot;
LL n;
int DEP;
int ans;
void init()
{
    for(int i=0;i<=60;i++)
    {
        b[i]=1ll<=0)sot.insert(s[DEP-1-dep]);//有到叶子距离为DEP-1-dep的完全二叉树
    }
    if(x&1)//如果在右面
    {
        LL lson=s[DEP-dep];//左面有这么大一棵树
        son+=lson+1;
    }
    else//如果在左面
    {
        LL rson=s[DEP-dep]>>1;//右面有这么大一棵树
        son+=rson+1;
    }
    go(dep-1,x>>1,son);
}
int main()
{
    init();
    while(~scanf("%lld",&n))
    {
        sot.clear();
        for(DEP=0;s[DEP]


你可能感兴趣的:(题库-HDU,脑洞,STL-set)