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. idea 连接数据库

    1:如果没有数据库连接插件,下载database插件 settings>plugin>Database Navigator 下载. 2:重启 3:进入 view>tool windo ...

  2. 四、Mosquitto 高级应用之用户配置

    本文将讲解 Mosquitto 用户机制.如果还没有搭建 Mosquitto 服务的可以参考我的另外两篇文章<< 一.Mosquitto 介绍&安装>> << ...

  3. gcc static静态编译选项提示错误修正(/usr/lib/ld: cannot find -lc)

    用gcc静态编译C程序时显示出: /usr/lib/ld: cannot find -lc /usr/lib/ld: cannot find -lgcc_s /usr/lib/ld: cannot f ...

  4. springmvc返回json数据的工具类

    在ssm框架下,MVC向前端返回数据的json工具类代码如下: public class JsonResult<T> { public static final int SUCCESS=0 ...

  5. Locust性能测试3-no-web模式和csv报告保存

    前言 前面是在web页面操作,需要手动的点start启动,结束的时候也需要手工去点stop,没法自定义运行时间,这就不太方便. locust提供了命令行运行的方法,不启动web页面也能运行,这就是no ...

  6. unity3d-小案例之角色简单漫游

    准备资源 我这里从网上下载一个角色模型,里面有一组动画.有站立.奔跑.杀怪等 我们来实现角色的前后左后移动,即键盘上的WSDA键,这里因为没有行走的动画.索性就用奔跑代替了!! 暂时先不计较代码冗余的 ...

  7. linux系统安装 dig和nslookup命令

    Fedora / Centos:1.yum install bind-utils Ubuntu: 1.sudo apt-get install dnsutils Debian: 1.2 apt-get ...

  8. 2:4 动态方法的调用(简化Action的配置)

    动态方法的第一种方法: 所以我们要手动设置 动态调用的开关打开:strus-core-jar里面:修改常量 使用方法: 根据请求来区分用哪个方法处理,处理完了,注意要在该方法里面返回与请求相同的字符串 ...

  9. AutoLayout 的一些坑

    1. 给一个 UIView 加约束,希望它显示在 UITableView 的底部,但是它不显示,它会出现在 UITableView 的顶部. 错误代码: [self.tableView addSubv ...

  10. 【CSS3】纯CSS代码实现模拟时钟,+js对时功能。

    使用CSS3纯代码来实现模拟时钟,及指针动画功能. 在这里主要使用到css3一些基本元素: border-radius:圆角边框,画圆形:表盘 Transform:变换,旋转,扭曲:刻度盘,指针形状 ...