Test instructions: Give a tree balance to determine whether it is balanced
Study Purple Book: The use of recursive first order input, the format of each balance is w1,d1,w2,d2, when the W1,W2 is 0, the input is a sub-balance.
In this way, whenever a sub-balance is entered, the balance is returned, and the &w value is passed, and the value of W is changed every time the solve function is called, and the judgment of a layer of sub-balances
Recursive understanding is still very difficult, and then hand push a sample, and then print the median value, slightly understand a lost = =
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cmath>5#include <algorithm>6 using namespacestd;7 8typedefLong LongLL;9 Ten BOOLSolveint&W) { One intw1,w2,d1,d2; A BOOLb1=true, b2=true; -Cin>>w1>>d1>>w2>>D2; - if(!W1) b1=solve (W1); the if(!W2) b2=solve (w2); -w=w1+W2; - //printf ("b1=%d\n", B1); - //printf ("b2=%d\n", B2); + //printf ("w=%d\n", W); - returnb1&&b2&& (w1*d1==w2*D2); + } A at intMain () - { - intt,w; -Cin>>T; - while(t--){ - if(Solve (W)) printf ("yes\n"); in Elseprintf"no\n"); - if(t) printf ("\ n"); to } + return 0; -}View Code
UVa 839 not so Mobile