http://acm.hdu.edu.cn/showproblem.php?pid=5524

Subtrees

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

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.(1≤N≤1018)
 
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
 
 
在Hack的时候截别人的代码, 然而我并不懂什么意思, 但相信自己以后会会的!!!
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm> typedef long long ll; using namespace std; ll ans= , Max=, n; void search(ll x)
{
ll lc=x, rc=x, dep=;
while(lc*<=n) lc *= , dep++;
while(rc*+<=n) rc = rc* + ; if(lc<=rc) Max = max(Max, dep);
else
{
search(x*);
search(x*+);
ans++;
}
} int main()
{
while(~scanf("%I64d", &n))
{
ans = ;
Max = ;
search();
printf("%I64d\n", ans+Max+);
}
return ;
}

代码1:

#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<set> using namespace std;
typedef long long ll;
set<ll> st;
set<ll>::iterator it; void deal(ll n)
{
ll k, t;
if((it=st.find(n)) !=st.end())
return ;
st.insert(n);
for(k=; k>=; k--)
{
if((1ll<<k)&(n+))break;
}
t = n - (1ll<<k) + ;
deal((1ll<<(k-)) +min(t, 1ll<<(k-))-);
deal((1ll<<(k-)) +max(0ll, t-(1ll<<(k-)))-);
} int main()
{
ll n; while(~scanf("%I64d", &n))
{
st.clear();
st.insert();
st.insert();
deal(n);
printf("%d\n", st.size()-);
}
return ;
}

代码2:

(树)Subtrees -- hdu -- 5524的更多相关文章

  1. hdu 5524 Subtrees dfs

    Subtrees Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Probl ...

  2. HDU 5524:Subtrees

    Subtrees  Accepts: 60  Submissions: 170  Time Limit: 2000/1000 MS (Java/Others)  Memory Limit: 13107 ...

  3. 【线段树】HDU 5493 Queue (2015 ACM/ICPC Asia Regional Hefei Online)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5493 题目大意: N个人,每个人有一个唯一的高度h,还有一个排名r,表示它前面或后面比它高的人的个数 ...

  4. 【线段树】HDU 5443 The Water Problem

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5443 题目大意: T组数据.n个值,m个询问,求区间l到r里的最大值.(n,m<=1000) ...

  5. 树链剖分处理+线段树解决问题 HDU 5029

    http://acm.split.hdu.edu.cn/showproblem.php?pid=5029 题意:n个点的树,m次操作.每次操作输入L,R,V,表示在[L,R]这个区间加上V这个数字.比 ...

  6. K-D树问题 HDU 4347

    K-D树可以看看这个博客写的真心不错!这里存个版 http://blog.csdn.net/zhjchengfeng5/article/details/7855241 HDU 4349 #includ ...

  7. 【线段树】HDU 1166 敌兵布阵

    这道题目是线段树里面最基础的单点更新问题. 设计的知识点包括线段树的单点更新和区间查询. 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1166 G++ ...

  8. 数据结构(主席树):HDU 5654 xiaoxin and his watermelon candy

    Problem Description During his six grade summer vacation, xiaoxin got lots of watermelon candies fro ...

  9. 主席树:HDU 4417 Super Mario

    Super Mario Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

随机推荐

  1. python 网络基础 之 网络协议

    osi 七层协议 互联网协议按照功能不同分为osi七层或者tcp/ip 五层或tcp/ip 四层 tcp/ip 四层 1.应用层 2.传输层 3.网络层 4.网络接口层 tcp/ip 五层 1.应用层 ...

  2. u-boot之make <board_name>_config执行过程分析

    从网上下载uboot源码之后需要对源码作相应修改来支持自己的开发板,更改完源码之后需要配置.uboot(make<board_name>_config).这里以百问网的开发板jz2440为 ...

  3. 循环&信息添加&颜色修改

            #import "AViewController.h" @interface AViewController () <UIActionSheetDelegat ...

  4. BZOJ 2733 [HNOI2012]永无乡 - 启发式合并主席树

    Description 1: 查询一个集合内的K大值 2: 合并两个集合 Solution 启发式合并主席树板子 Code #include<cstdio> #include<cst ...

  5. C++ 的虚析构函数

    当一个基类的指针指向一个派生类的对象,并用该基类的指针去删除或者析构派生类对象时,如果基类的析构函数不是声明为虚函数,那么在析构时基类的析构函数将会被直接调用,派生类的析构函数应为没被调用而导致内存泄 ...

  6. tp5查看版本

    5.0 base.php 5.1 echo \think\facade\App::version();//用这行代码查看版本

  7. b2c项目访问

    http://xmpw.testbase.smi170.com:8091/member/movie_coupon_new.php

  8. 含有选择器的 bootstrap菜单

    var menu = new BootstrapMenu('#jsmind_container jmnode:not(.root)', { actions: [{ name: '展开节点', onCl ...

  9. openssl初步使用

    centos平台 md5.c #include <stdio.h> #include <string.h> #include <stdlib.h> //#inclu ...

  10. 【记录】解决VS2015调试Xamarin程序一闪而过(使用微软ANDROID模拟器)

    越来越多的人去安装Visual Studio 2015,也会去试试其中的C#跨平台开发利器Xamarin,但是也会发现很多问题. 我相信我不会是唯一遇到以下问题的,也不会是最后一个,特此记录. 微软的 ...