-
Notifications
You must be signed in to change notification settings - Fork 0
/
P104.java
61 lines (38 loc) · 1.42 KB
/
P104.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package aceptaelreto;
import java.util.*;
class movils {
int pi,di,pd,dd;
movils der, izq;
movils(int pi,int di,int pd,int dd) {
this.pi = pi; this.di = di; this.pd = pd; this.dd = dd;
}
}
public class P104 {
static Scanner s;
static boolean equilibrio(movils m) {
boolean izq = true;
if (m.pi == 0) {
m.izq = new movils(s.nextInt(), s.nextInt(), s.nextInt(), s.nextInt());
izq = equilibrio(m.izq);
m.pi = m.izq.pi + m.izq.pd;
}
boolean der = true;
if (m.pd == 0) {
m.der = new movils(s.nextInt(), s.nextInt(), s.nextInt(), s.nextInt());
der = equilibrio(m.der);
m.pd = m.der.pi + m.der.pd;
}
return (der && izq) && (m.pi * m.di == m.pd * m.dd);
}
static boolean cas() {
movils m = new movils(s.nextInt(), s.nextInt(), s.nextInt(), s.nextInt());
if (m.pi == 0 && m.pd == 0 && m.di == 0 && m.dd == 0) return false;
System.out.println(equilibrio(m)? "SI" : "NO");
return true;
}
public static void main(String[] args) {
s = new Scanner(System.in);
while (cas());
s.close();
}
}