How do you get the AC without charging?
Title: http://codevs.cn/problem/3143/
A flood problem, as long as it will traverse, here to talk about ideas
First Order traversal: first output, then left son, last right son
Middle sequence traversal: first left son, then output, last right son
Post-post traversal: first left son, then right son, final output
1#include <cstdio>2#include <cstdlib>3#include <cstring>4#include <cmath>5#include <iostream>6#include <algorithm>7 #defineN 208 using namespacestd;9 Ten intL[n],r[n],n; One voidQianintx) A { - if(x==0)return; -printf"%d", x); the Qian (l[x]); - Qian (r[x]); - } - voidZhongintx) + { - if(x==0)return; + Zhong (l[x]); Aprintf"%d", x); at Zhong (r[x]); - } - voidHouintx) - { - if(x==0)return; - Hou (l[x]); in Hou (r[x]); -printf"%d", x); to } + intMain () - { the inti; *scanf"%d",&n); $ for(i=1; i<=n;i++) scanf ("%d%d",&l[i],&r[i]);Panax NotoginsengQian1); -printf"\ n"); theZhong1); +printf"\ n"); AHou1); theprintf"\ n"); + return 0; -}
[Codevs Cup Road] P3143