UVa 839 Not so Mobile

Code:
 1  #include<stdio.h>
 2  #include<stdlib.h>
 3  #include<iostream>
 4  #include<algorithm>
 5  using namespace std;
 6  bool solve(int &w)
 7  {
 8      int w1,d1,w2,d2;
 9      cin>>w1>>d1>>w2>>d2;
10      bool left=true,right=true;
11      if(w1==0) left=solve(w1);
12      if(w2==0) right=solve(w2);
13      w=w1+w2;
14      return left && right && (d1*w1==d2*w2);
15 
16  }
17  int main()
18  {
19      int cas,w;
20      cin>>cas;
21      while(cas--)
22      {
23          w=0;
24          if(solve(w)) cout<<"YES"<<endl;
25          else cout<<"NO"<<endl;
26          if(cas) cout<<endl;
27      }
28      return 0;

29  }

留言

這個網誌中的熱門文章

Things a Little Bird Told Me: Confessions of the Creative Mind

UVa 12970 Alcoholic Pilots

UVa 483 Word Scramble