-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThatDelicateBalance.java
More file actions
80 lines (62 loc) · 2.04 KB
/
Copy pathThatDelicateBalance.java
File metadata and controls
80 lines (62 loc) · 2.04 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
//2005 - #4
import java.util.*;
public class ThatDelicateBalance {
public static double thatFunction(double num){
//The function?
double sum = 0.0;
for(double x = 0.0; x <= num; x++){
sum += Math.pow(3.0, x);
}
return sum;
}
public static void main(String[] args){
Scanner input = new Scanner(System.in);
int times = input.nextInt();
for(int i = 0; i < times; i++){
int initialWeight = input.nextInt();
int leftW = initialWeight;
int rightW = 0;
ArrayList<Integer> jValues = new ArrayList<Integer>();
for(int x = 0; x < 20; x++){
jValues.add(x);
}
ArrayList<Integer> basketR = new ArrayList<Integer>();
ArrayList<Integer> basketL = new ArrayList<Integer>();
while(true){
int w = leftW - rightW;
if(w == 0){
//solved
//TODO output
System.out.print(initialWeight + " ");
Collections.sort(basketR);
Collections.sort(basketL);
//TODOTODOTODOTODOTODOTODO
for(int x = 0; x < basketR.size(); x++){
System.out.print(basketR.get(x) + " ");
}
for(int x = 0; x < basketL.size(); x++){
System.out.print(basketL.get(x) + " ");
}
System.out.println();
}
for(int j = 0; j < jValues.size() - 1; j++){
if((thatfunction(jValues.get(j)) < Math.abs(w)) && thatfunction(jValues.get(j) + 1) > Math.abs(w)){//Fiddle with this
//We have the j we're looking for
//Place the weight 3^j into lighter basket
if(w > 0){
//right is lighter basket
rightW += Math.pow(3, j);
basketR.add(-1 * Math.pow(3, j));
jValues.remove(jValues.indexOf(j));
} else {
//left is lighter basket
leftW += Math.pow(3, j);
basketL.add(Math.pow(3, j));
jValues.remove(jValues.indexOf(j));
}
}
}
}//End while
}
}
}