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. logstash的各个场景应用(配置文件均已实践过)

    场景: 1) datasource->logstash->elasticsearch->kibana 2) datasource->filebeat->logstash- ...

  2. ComBSTR的使用

    用 CComBSTR 进行编程 Visual Studio .NET 2003   3(共 3)对本文的评价是有帮助 - 评价此主题   ATL 类 CComBSTR 提供对 BSTR 数据类型的包装 ...

  3. testng入门教程10 TestNG参数化测试

    在TestNG的另一个有趣的功能是参数测试.在大多数情况下,你会遇到这样一个场景,业务逻辑需要一个巨大的不同数量的测试.参数测试,允许开发人员运行同样的测试,一遍又一遍使用不同的值. TestNG让你 ...

  4. Header实现文件下载

    function download($file){ //文件根路径 $filename=$_SERVER['DOCUMENT_ROOT'].__ROOT__.'/'.$file; //下载文件 if( ...

  5. mongodb mongotemplate聚合

    1.group by并且计算总数 @Test public void insertTest() { //测试数据 //insertTestData(); Aggregation agg = Aggre ...

  6. FastReport问题整理(转)

    FastReport问题整理 博客分类: 软件开发   部分来自网上,部分来自网友,部分来自Demo如果有新的内容,会不断更新.. 更新历史: 2009-02-27 加入套打方案全攻略(原:jinzh ...

  7. AdaBoost学习笔记

    学习了李航<统计学习方法>第八章的提升方法,现在对常用的一种提升方法AdaBoost作一个小小的笔记,并用python实现书本上的例子,加深印象.提升方法(boosting)是一种常用的统 ...

  8. Linux基础命令---unzip

    unzip 解压zip指令压缩过的文件.unzip将列出.测试或从ZIP存档中提取文件,这些文件通常在MS-DOS系统中找到.默认行为(没有选项)是将指定ZIP存档中的所有文件提取到当前目录(及其下面 ...

  9. QImage与QPixmap完全解析

    转载自http://www.civilnet.cn/bbs/browse.php?topicno=4691 用Qt程序在手机上显示一幅图片对编程人员来说是再基础不过的一件事情了.那么先让大家看两段代码 ...

  10. python之路----面向对象的继承特性

    继承 什么是继承 继承是一种创建新类的方式,在python中,新建的类可以继承一个或多个父类,父类又可称为基类或超类,新建的类称为派生类或子类 python中类的继承分为:单继承和多继承 class ...