Skip to content

Commit b15f0f7

Browse files
committed
Add AOJ1181/AOJ1248/AOJ1315/SRM625
1 parent 1b30050 commit b15f0f7

File tree

11 files changed

+461
-0
lines changed

11 files changed

+461
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
1+
// Biased Dice
2+
import java.util.*;
3+
4+
public class Main {
5+
static final int CENTER = 100;
6+
static int[][] heights;
7+
8+
public static void main(String[] args) {
9+
Scanner sc = new Scanner(System.in);
10+
while (true) {
11+
int n = sc.nextInt();
12+
if (n == 0)
13+
break;
14+
heights = new int[201][201];
15+
int[][] tops = new int[201][201];
16+
for (int i = 0; i < n; i++) {
17+
int t = sc.nextInt(), f = sc.nextInt();
18+
Dice dice = new Dice(t, f);
19+
while (dice.canRoll())
20+
dice.roll();
21+
tops[dice.x][dice.y] = dice.top;
22+
}
23+
int[] result = new int[6];
24+
for (int i = 0; i < 201; i++)
25+
for (int j = 0; j < 201; j++)
26+
if (tops[i][j] > 0)
27+
result[tops[i][j] - 1]++;
28+
for (int i = 0; i < 5; i++)
29+
System.out.print(result[i] + " ");
30+
System.out.println(result[5]);
31+
}
32+
sc.close();
33+
}
34+
35+
static class Dice {
36+
int top, front, right;
37+
int x, y, height, dir;
38+
39+
Dice(int t, int f) {
40+
top = t;
41+
front = f;
42+
x = CENTER;
43+
y = CENTER;
44+
height = heights[x][y] + 1;
45+
heights[x][y]++;
46+
switch (t) {
47+
case 1:
48+
switch (f) {
49+
case 2:
50+
right = 3;
51+
break;
52+
case 3:
53+
right = 5;
54+
break;
55+
case 4:
56+
right = 2;
57+
break;
58+
case 5:
59+
right = 4;
60+
break;
61+
}
62+
break;
63+
case 2:
64+
switch (f) {
65+
case 1:
66+
right = 4;
67+
break;
68+
case 3:
69+
right = 1;
70+
break;
71+
case 4:
72+
right = 6;
73+
break;
74+
case 6:
75+
right = 3;
76+
break;
77+
}
78+
break;
79+
case 3:
80+
switch (f) {
81+
case 1:
82+
right = 2;
83+
break;
84+
case 2:
85+
right = 6;
86+
break;
87+
case 5:
88+
right = 1;
89+
break;
90+
case 6:
91+
right = 5;
92+
break;
93+
}
94+
break;
95+
case 4:
96+
switch (f) {
97+
case 1:
98+
right = 5;
99+
break;
100+
case 2:
101+
right = 1;
102+
break;
103+
case 5:
104+
right = 6;
105+
break;
106+
case 6:
107+
right = 2;
108+
break;
109+
}
110+
break;
111+
case 5:
112+
switch (f) {
113+
case 1:
114+
right = 3;
115+
break;
116+
case 3:
117+
right = 6;
118+
break;
119+
case 4:
120+
right = 1;
121+
break;
122+
case 6:
123+
right = 4;
124+
break;
125+
}
126+
break;
127+
case 6:
128+
switch (f) {
129+
case 2:
130+
right = 4;
131+
break;
132+
case 3:
133+
right = 2;
134+
break;
135+
case 4:
136+
right = 5;
137+
break;
138+
case 5:
139+
right = 3;
140+
break;
141+
}
142+
break;
143+
}
144+
}
145+
146+
void rollR() {
147+
x++;
148+
int t = 7 - right;
149+
right = top;
150+
top = t;
151+
}
152+
153+
boolean canRoll() {
154+
int[] d = { front, 7 - front, right, 7 - right };
155+
int[] dx = { 0, 0, 1, -1 };
156+
int[] dy = { 1, -1, 0, 0 };
157+
for (int i = 6; i >= 4; i--) {
158+
for (int j = 0; j < 4; j++) {
159+
if (i == d[j]
160+
&& heights[x][y] - 1 > heights[x + dx[j]][y + dy[j]]) {
161+
dir = j;
162+
return true;
163+
}
164+
}
165+
}
166+
return false;
167+
}
168+
169+
void roll() {
170+
heights[x][y]--;
171+
switch (dir) {
172+
case 0:
173+
rollF();
174+
break;
175+
case 1:
176+
rollB();
177+
break;
178+
case 2:
179+
rollR();
180+
break;
181+
case 3:
182+
rollL();
183+
break;
184+
}
185+
heights[x][y]++;
186+
height = heights[x][y];
187+
}
188+
189+
void rollL() {
190+
x--;
191+
int t = 7 - top;
192+
top = right;
193+
right = t;
194+
}
195+
196+
void rollF() {
197+
y++;
198+
int t = 7 - front;
199+
front = top;
200+
top = t;
201+
}
202+
203+
void rollB() {
204+
y--;
205+
int t = 7 - top;
206+
top = front;
207+
front = t;
208+
}
209+
}
210+
}

AizuOnlineJudge/ProblemSets11/1181_Biased_Dice/README.md

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// The Balance
2+
import java.util.*;
3+
4+
public class Main {
5+
public static void main(String[] args) {
6+
Scanner sc = new Scanner(System.in);
7+
while (true) {
8+
int a = sc.nextInt(), b = sc.nextInt(), d = sc.nextInt();
9+
if ((a | b | d) == 0)
10+
break;
11+
int x = 100000, y = 100000;
12+
for (int i = 0; i <= x + y; i++)
13+
for (int j = 0; i + j <= x + y; j++) {
14+
while (a * i - b * j > d)
15+
j++;
16+
if (b * j - a * i > d)
17+
break;
18+
if (a * i == b * j + d || a * i + b * j == d
19+
|| b * j == a * i + d) {
20+
if (i + j < x + y) {
21+
x = i;
22+
y = j;
23+
continue;
24+
}
25+
if (i + j == x + y && a * i + b * j < a * x + b * y) {
26+
x = i;
27+
y = j;
28+
}
29+
}
30+
}
31+
System.out.println(x + " " + y);
32+
}
33+
sc.close();
34+
}
35+
}

AizuOnlineJudge/ProblemSets12/1248_The_Balance/README.md

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import java.util.*;
2+
3+
public class Main {
4+
public static void main(String[] args) {
5+
Scanner sc = new Scanner(System.in);
6+
while (true) {
7+
int n = sc.nextInt();
8+
if (n == 0)
9+
break;
10+
int[] etimes = new int[1000];
11+
int[] times = new int[1000];
12+
String currentDay = "";
13+
for (int i = 0; i < n; i++) {
14+
String day = sc.next();
15+
String time = sc.next();
16+
char io = sc.next().charAt(0);
17+
int id = sc.nextInt();
18+
if (!day.equals(currentDay)) {
19+
currentDay = day;
20+
for (int j = 1; j < 1000; j++)
21+
if (etimes[i] != 0) {
22+
etimes[i] = 0;
23+
if (etimes[0] != 0)
24+
etimes[i] += 24 * 60 - 1 - etimes[i];
25+
}
26+
etimes[0] = 0;
27+
}
28+
if (io == 'I') {
29+
String[] s = time.split(":");
30+
int t = Integer.parseInt(s[0]) * 60
31+
+ Integer.parseInt(s[1]);
32+
etimes[id] = t;
33+
} else {
34+
String[] s = time.split(":");
35+
int otimes = Integer.parseInt(s[0]) * 60
36+
+ Integer.parseInt(s[1]);
37+
if (id == 0) {
38+
for (int j = 1; j < 1000; j++)
39+
if (etimes[j] != 0)
40+
times[j] += otimes
41+
- Math.max(etimes[0], etimes[j]);
42+
} else if (etimes[0] != 0)
43+
times[id] += otimes - Math.max(etimes[0], etimes[id]);
44+
etimes[id] = 0;
45+
}
46+
}
47+
int result = 0;
48+
for (int i = 1; i < 1000; i++) {
49+
result = Math.max(result, times[i]);
50+
}
51+
System.out.println(result);
52+
}
53+
sc.close();
54+
}
55+
}

AizuOnlineJudge/ProblemSets13/1315_Gift_from_the_Goddess_of_Programming/README.md

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
public class AddMultiply {
2+
3+
public int[] makeExpression(int y) {
4+
return new int[] { -1, 2, y + 2 };
5+
}
6+
7+
}

TopCoder/SRMs/SRM625/Div2_250_AddMultiply/README.md

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import java.util.Arrays;
2+
3+
public class IncrementingSequence {
4+
5+
public String canItBeDone(int k, int[] A) {
6+
boolean[] B = new boolean[A.length];
7+
Arrays.fill(B, true);
8+
out: for (int i = 1; i <= A.length; i++) {
9+
for (int j = 0; j < A.length; j++)
10+
if (B[j] && A[j] == i) {
11+
B[j] = false;
12+
continue out;
13+
}
14+
for (int j = 0; j < A.length; j++)
15+
if (B[j] && (A[j] - i) % k == 0) {
16+
B[j] = false;
17+
continue out;
18+
}
19+
return "IMPOSSIBLE";
20+
}
21+
return "POSSIBLE";
22+
}
23+
24+
}

TopCoder/SRMs/SRM625/Div2_500_IncrementingSequence/README.md

Whitespace-only changes.

0 commit comments

Comments
 (0)