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. Java 和 Javascript的关系

    写这篇文章是因为看到有人问这个问题,在想怎么会有这种SB问题,不过想想当初SB的我貌似也搞不清两者的关系,认知还是需要一个过程. 然后看到比较经典的回答有:Java 和Javascript的关系就像雷 ...

  2. PAT 1063 计算谱半径(20)(代码)

    1063 计算谱半径(20 分) 在数学中,矩阵的"谱半径"是指其特征值的模集合的上确界.换言之,对于给定的 n 个复数空间的特征值 { a​1​​+b​1​​i,⋯,a​n​​+ ...

  3. 796B Find The Bone

    B. Find The Bone time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...

  4. linux 使用笔记3

    解决linux下打开txt乱码问题 在Linux下要阅读windows生成的txt文件,需要通过iconv进行字符转化 iconv -f gb2312 -t utf8 ./读书笔记.txt > ...

  5. Python GUI中 text框里实时输出

    首先GUI中不同函数的局部变量的问题. 发现不同button定义的函数得到的变量无法通用. 通过global 函数内的变量可以解决这个问题 def openfiles2(): global s2fna ...

  6. Maximum Size Subarray Sum Equals k LT325

    Given an array nums and a target value k, find the maximum length of a subarray that sums to k. If t ...

  7. HttpMethods(C#.net)

    HttpMethods  (C#.Net) using System; using System.Collections.Generic; using System.Linq; using Syste ...

  8. springMVC学习一 工作机制

    springMVC下面的四大组件: (1)DispatcherServlet : 前端控制器,接收所有请求 ,并把请求路径和请求参数解析出来,本质是一个servlet在web.xml中配置 (如果配置 ...

  9. Linux下进行程序设计时,关于库的使用:

    一.gcc/g++命令中关于库的参数: -shared: 该选项指定生成动态连接库: -fPIC:表示编译为位置独立(地址无关)的代码,不用此选项的话,编译后的代码是位置相关的,所以动态载入时,是通过 ...

  10. 783. Minimum Distance Between BST Node

    方法一,非递归方法,中序遍历 /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *l ...