UVa 839 Not so Mobile

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.