input

n 1<=n<=1e18

output

有n个结点的满二叉树有多少个不相同结点数的子树

做法:树有h=log2(n)层,最多有2h-2种(1除外),然后再n减去u重复的即可

 #include <bits/stdc++.h>
#include <cstdio>
#include <queue>
#include <cstring>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <ctime>
#include <cmath>
#include <cctype>
#include <string>
#include <bitset>
#define MAX 100000
#define LL long long
using namespace std;
LL n;
int highbit(LL x)
{
for(int i=;i>=;i--) if(x&(1LL<<i)) return i+;
}
int lowbit(LL x)
{
for(int i=;i<=;i++) if(x&(1LL<<i)) return i;
}
int main()
{
freopen("in","r",stdin);
//scanf("%d",&T);
while(scanf("%lld",&n)==)
{
int h=highbit(n);
LL maxn=(1LL<<h)-;LL mid=maxn-(1LL<<(h->=?h-:));
// printf("%lld:",n);
// printf("h=%d maxn=%lld mid=%lld\n",h,maxn,mid);
if(n==maxn||n==mid) { printf("%d\n",h);continue; }
h+=h-;
if(n<=mid) h--;
h-=lowbit(n-(maxn>>));
printf("%d\n",h);
}
//printf("time=%.3lf",(double)clock()/CLOCKS_PER_SEC);
return ;
}

hdu 5524 二叉树找规律,二进制相关的更多相关文章

  1. HDU 2086 A1 = ? (找规律推导公式 + 水题)(Java版)

    Equations 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2086 ——每天在线,欢迎留言谈论. 题目大意: 有如下方程:Ai = (Ai-1 ...

  2. hdu 5047 大数找规律

    http://acm.hdu.edu.cn/showproblem.php?pid=5047 找规律 信kuangbin,能AC #include <stdio.h> #include & ...

  3. hdu5573 二叉树找规律,二进制相关

    input T 1<=T<=100 n k 1<=n<=1e9  n<=2^k<=2^60 output 从1走到第k层,下一层的数是上一层的数×2或者×2+1,每 ...

  4. hdu 5106 组合数学+找规律

    http://acm.hdu.edu.cn/showproblem.php?pid=5106 给定n和r,要求算出[0,r)之间所有n-onebit数的和,n-onebit数是所有数位中1的个数. 对 ...

  5. hdu 4759 大数+找规律 ***

    题目意思很简单. 就是洗牌,抽出奇数和偶数,要么奇数放前面,要么偶数放前面. 总共2^N张牌. 需要问的是,给了A X B Y  问经过若干洗牌后,第A个位置是X,第B个位置是Y 是不是可能的. Ja ...

  6. Doom HDU - 5239 (找规律+线段树)

     题目链接: D - Doom  HDU - 5239  题目大意:首先是T组测试样例,然后n个数,m次询问,然后每一次询问给你一个区间,问你这个这段区间的加上上一次的和是多少,查询完之后,这段区间里 ...

  7. Full Binary Tree(二叉树找规律)

    Description In computer science, a binary tree is a tree data structure in which each node has at mo ...

  8. hdu 4708(暴力+找规律)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4708 思路:由于N不大,并且我们可以发现通过旋转得到的4个对角线的点的位置关系,以及所要旋转的最小步数 ...

  9. HDU 5084 HeHe --找规律

    题意: 给出矩阵M,求M*M矩阵的r行c列的数,每个查询跟前一个查询的结果有关. 解法: 观察该矩阵得知,令ans = M*M,则 ans[x][y] = (n-1-x行的每个值)*(n-1+y列的每 ...

随机推荐

  1. Java NIO Path接口和Files类配合操作文件

    Java NIO Path接口和Files类配合操作文件 @author ixenos Path接口 1.Path表示的是一个目录名序列,其后还可以跟着一个文件名,路径中第一个部件是根部件时就是绝对路 ...

  2. AnimatorController反向运动学IK

    通过使用反向运动学IK,我们可以根据需要控制角色身体某个特定部位进行旋转或移动,达到想要的一些效果,比如:在移动时,让一只脚带伤拖行:让手抬起去拿桌上的苹果:让脑袋一直面向我们的色像机,就像一直注视着 ...

  3. Excel的 OleDb 连接串的格式(Provider=Microsoft.ACE.OLEDB)

    string strCon = "Provider=Microsoft.ACE.OLEDB.12.0;data source=" + filePath + ";Exten ...

  4. Java基础之异常

    1.异常的概念 异常:程序在运行时出现的不正常情况,也可以说是出现的问题: Java中的异常:出现的不正常的问题也是一类事物,这类事物有一些共性的东西,比如有名称,有产生的原因等,将这些共性的部分抽取 ...

  5. vue的测试(Vue.js devtool)

    1. 安装chrome插件:Vue.js devtools(https://chrome.google.com/webstore/detail/vuejs-devtools/nhdogjmejigli ...

  6. linux 调整文件系统大小 LVM

    fuser -m /home umount /home lvreduce -L 150G /dev/mapper/centos-home lvextend -L +300G /dev/mapper/c ...

  7. 从安装.net Core 到helloWord(Mac上)

    最近听说微软 正式发不了.netCore 1.0 于是就安装了 并安装了vs Code 用于编写一些.net程序 一. .netCore的安装: 首先需要通过brew安装openssl(相信homeB ...

  8. Code Sign error: No code signing identities found: No valid signing identities

    Code Sign error: No code signing identities found: No valid signing identities 解决办法:如果证书可获取,最简办法就是把所 ...

  9. 关于jQuery表单校验

    <style> .red{border: 1px solid red;} .wrong-tip{color: red;} </style> <form action=&q ...

  10. wakeup_train运行遇到的问题记录

      运行前需要更改的地方:   1.matlab安装的路径以及matlab的license文件     2.噪声的路径;background.scp,以及噪声文件     3.run.sh文件中一处f ...