Topic Links:
https://vijos.org/p/1114
Main Topic :
Put 01 strings in half, the left side describes the current node left subtree, the right half describes the right subtree, the subtree is all 1 is the I node, all 0 is a b node, mixed is the F node, until the current string length of 1 stop.
Given 01 strings, ask the FBI tree to order.
Topic Ideas:
"Recursion"
Each operation first operation of the left subtree, and then the right subtree, and then statistics about the subtree 01 state, according to the requirements of the current node is F B I in which.
Since the output is sequential, the node can be output after each operation of the left and right subtree, and the current string length is 1 and the output is returned.
1 //2 //by Coolxxx3 //4#include <iostream>5#include <algorithm>6#include <string>7#include <iomanip>8#include <memory.h>9#include <time.h>Ten#include <stdio.h> One#include <stdlib.h> A#include <string.h> -#include <stdbool.h> -#include <math.h> the #defineMin (a) < (b) ( A):(B)) - #defineMax (a) (a) > (b)? ( A):(B)) - #defineABS (a) ((a) >0? ( A):(-(a))) - #defineLowbit (a) (a& (a)) + #defineSqr (a) ((a) * (a)) - #defineSwap (a) (a) ^= (b), (b) ^= (a), (a) ^= (b)) + #defineEPS 1e-8 A #defineJ 10000 at #defineMAX 0x7f7f7f7f - #definePI 3.1415926535897 - #defineN 1504 - using namespacestd; - intN,m,lll,ans,cas; - inte[]={1,2,4,8, -, +, -, -, the, +,1024x768}; in CharS[n]; - Charp[]={'B','I','F'}; to intWorkintLintR) + { - intLl,rr,mid= (l+r) >>1; the if(l==R) * { $printf"%c", p[s[l]=='1']);Panax Notoginseng return(s[l]=='1'); - } theLl=Work (l,mid); +Rr=work (mid+1, R); A if(ll==RR) the { +printf"%c", P[ll]); - returnll; $ } $ Else - { -printf"%c"-P:2]); the return 2; - }Wuyi } the intMain () - { Wu #ifndef Online_judge - //freopen ("1.txt", "R", stdin); About //freopen ("2.txt", "w", stdout); $ #endif - inti,j,k; - //while (~scanf ("%s", S1)) - while(~SCANF ("%d",&N)) A { +scanf"%s", s); theWork0, e[n]-1); -Puts""); $ } the return 0; the } the the - /* in // the the // About */
View Code
"Recursion" Vijos P1114 FBI tree (the third problem of the NOIP2004 popularization group)