Subtrees

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

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
 
 
题意:给你一颗n个节点的完全二叉树找出子树中个数不同的个数;

就是如果左子树和右子树相同只需要遍历一颗子树即可;

不同遍历两颗;
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<queue>
#include<algorithm>
#include<stack>
#include<cstring>
#include<vector>
#include<list>
#include<set>
#include<map>
using namespace std;
#define ll long long
#define pi (4*atan(1.0))
#define eps 1e-14
#define bug(x) cout<<"bug"<<x<<endl;
const int N=2e3+,M=4e6+,inf=;
const ll INF=1e18+,mod=1e9+; /// 数组大小 set<ll>ans;
map<ll,ll>si;
ll n;
void dfs(ll x)
{
if(x>n)return;
ll l=x,r=x;
while(l*<=n)l*=;
while(r*+<=n)r=r*+;
if(l==x&&r==x)
{
si[x]=;
ans.insert();
return;
}
if(l<=r)
{
dfs(x*);
si[x]=*si[x*]+;
ans.insert(si[x]);
//cout<<x<<" "<<si[x]<<endl;
}
else
{
dfs(x*);
dfs(x*+);
si[x]=si[x*]+si[x*+]+;
//cout<<x<<" "<<si[x]<<" "<<si[x*2]<<" "<<si[x*2+1]<<endl;
ans.insert(si[x]);
}
}
int main()
{
while(~scanf("%lld",&n))
{
ans.clear();
si.clear();
dfs();
printf("%d\n",ans.size());
}
return ;
}

hdu 5524 Subtrees dfs的更多相关文章

  1. (树)Subtrees -- hdu -- 5524

    http://acm.hdu.edu.cn/showproblem.php?pid=5524 Subtrees Time Limit: 2000/1000 MS (Java/Others)    Me ...

  2. HDU.5692 Snacks ( DFS序 线段树维护最大值 )

    HDU.5692 Snacks ( DFS序 线段树维护最大值 ) 题意分析 给出一颗树,节点标号为0-n,每个节点有一定权值,并且规定0号为根节点.有两种操作:操作一为询问,给出一个节点x,求从0号 ...

  3. HDU 5524:Subtrees

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

  4. hdu 5727 Necklace dfs+二分图匹配

    Necklace/center> 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5727 Description SJX has 2*N mag ...

  5. hdu 4499 Cannon dfs

    Cannon Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4499 D ...

  6. hdu 1175 连连看 DFS

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1175 解题思路:从出发点开始DFS.出发点与终点中间只能通过0相连,或者直接相连,判断能否找出这样的路 ...

  7. HDU 5547 Sudoku(DFS)

    题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=5547 题目: Sudoku Time Limit: 3000/1000 MS (Java/Others ...

  8. F - Auxiliary Set HDU - 5927 (dfs判断lca)

    题目链接: F - Auxiliary Set HDU - 5927 学习网址:https://blog.csdn.net/yiqzq/article/details/81952369题目大意一棵节点 ...

  9. hdu 4714 树+DFS

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4714 本来想直接求树的直径,再得出答案,后来发现是错的. 思路:任选一个点进行DFS,对于一棵以点u为 ...

随机推荐

  1. dp训练

    根据这位大佬的https://www.cnblogs.com/Bunnycxk/p/7360183.html 题目链接:https://www.luogu.org/problemnew/show/P3 ...

  2. VMware Coding Challenge: The Heist

    类似BackpackII问题 static int maximize_loot(int[] gold, int[] silver) { int[][] res = new int[gold.lengt ...

  3. ubuntu shell脚本出错 dash

    今天在Ubuntu下调试代码,明明是正确的,却仍然报错,查了错误信息才知道:Ubuntu中默认不是bash,而是为了加快开机速度,使用了dash. dash中需要严格的语法,而且与bash语法不同.例 ...

  4. Qt界面控件值获取异常处理

    情景简述: 正常情况,我们从控件获取的值是OK的,但有时候就是奇怪的不对头,那么我们可以给获取后的值加上一个不痛不痒的函数,再返回,结果就OK了.至于原因嘛,[呲牙][呲牙] 比如: //正常情况 d ...

  5. 机器学习中的范数规则化 L0、L1与L2范数 核范数与规则项参数选择

    http://blog.csdn.net/zouxy09/article/details/24971995 机器学习中的范数规则化之(一)L0.L1与L2范数 zouxy09@qq.com http: ...

  6. 本地缓存之GUAVA

    项目开发中,很多配置数据需要缓存,一般来说,开发人员都会手动写HashMap,HashSet或者ConcurrentHashMap,ConcurrentHashSet缓存数据,但是这样的缓存往往存在内 ...

  7. 20165207 2017-2018-2《Java程序设计》课程总结

    20165207 2017-2018-2<Java程序设计>课程总结 每周作业链接汇总 预备作业1:我期望的师生关系 预备作业2:学习基础与C语言调查反馈 预备作业3:Linux安装与命令 ...

  8. ThinkPHP CURD mysql操作

    ThinkPHP CURD操作 ThinkPHP提供了灵活和方便的数据操作方法,对数据库操作的四个基本操作(CURD):创建.更新.读取和删除的实现是最基本的,也是必须掌握的,在这基础之上才能熟悉更多 ...

  9. 从1.6W名面试者中收集的Java面试题精选汇总(内附知识脑图)

      本篇的面试题是接之前读者的要求,发出来的. 首先,声明下,以下知识点并非全部来自BAT的面试题. 如果觉得在本文中笔者总结的内容能对你有所帮助,可以点赞关注一下. 本文会以引出问题为主,后面有时间 ...

  10. JavaScript计算星期几

    function zeller(dateStr) { var c = parseInt(dateStr.substr(0, 2)); var y = parseInt(dateStr.substr(2 ...