Advertisement
Guest User

Untitled

a guest
Nov 26th, 2014
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.98 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class Main {
  3.     public static void main(String[] args) {
  4.         // TODO Auto-generated method stub
  5.         Scanner in = new Scanner(System.in);
  6.         long testcases = in.nextLong();
  7.         for(int i = 0; i < testcases; i++){
  8.             Node start = new Node();
  9.             if(start.Balanced())
  10.                 System.out.println("YES");
  11.             else
  12.                 System.out.println("NO");
  13.             System.out.println();
  14.         }  
  15.     }
  16. }
  17. class Node {
  18.     public long Wl, Dl, Wr, Dr;
  19.     public Node(){
  20.         Scanner in = new Scanner(System.in);
  21.         Wl = in.nextLong();
  22.         Dl = in.nextLong();
  23.         Wr = in.nextLong();
  24.         Dr = in.nextLong();
  25.     }
  26.    
  27.     public boolean Balanced(){
  28.         if(WeightL() * Dl == WeightR() * Dr){
  29.             return true;
  30.         }
  31.         else return false;
  32.     }
  33.    
  34.     public long WeightL(){
  35.         if(Wl == 0){
  36.             Node child = new Node();
  37.             Wl = child.WeightL() + child.WeightR();
  38.         }
  39.         return Wl;
  40.     }
  41.    
  42.     public long WeightR(){
  43.         if(Wr == 0){
  44.             Node child = new Node();
  45.             Wr = child.WeightL() + child.WeightR();
  46.         }
  47.         return Wr;
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement