Input
N 1<=n<=1e18
Output
How many sub-trees with a number of different nodes in a two-ary tree with n nodes
Practice: The tree has H=LOG2 (n) layer, up to 2h-2 species (except 1), and then n minus u repeat
1#include <bits/stdc++.h>2#include <cstdio>3#include <queue>4#include <cstring>5#include <iostream>6#include <cstdlib>7#include <algorithm>8#include <vector>9#include <map>Ten#include <Set> One#include <ctime> A#include <cmath> -#include <cctype> -#include <string> the#include <bitset> - #defineMAX 100000 - #defineLL Long Long - using namespacestd; + LL N; - inthighbit (LL x) + { A for(intI= the; i>=0; i--)if(x& (1ll<<i))returni+1; at } - intlowbit (LL x) - { - for(intI=0; i<= the; i++)if(x& (1ll<<i))returni; - } - intMain () in { -Freopen ("inch","R", stdin); to //scanf ("%d", &t); + while(SCANF ("%lld", &n) = =1) - { the intH=highbit (n); *LL maxn= (1ll<1; LL mid=maxn-(1ll<< (H2>=0? H-2:0)); $ //printf ("%lld:", n);Panax Notoginseng //printf ("h=%d maxn=%lld mid=%lld\n", h,maxn,mid); - if(n==maxn| | N==mid) {printf ("%d\n", h);Continue; } theh+=h-2; + if(N<=mid) h--; AH-=lowbit (N-(maxn>>1)); theprintf"%d\n", h); + } - //printf ("Time=%.3lf", (double) clock ()/clocks_per_sec); $ return 0; $}
View Code
Hdu 55,242 Cross-tree search rules, binary correlation