-
Notifications
You must be signed in to change notification settings - Fork 7
/
CoinCounter.java
63 lines (62 loc) · 2.37 KB
/
CoinCounter.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
62
63
import java.awt.*;
import java.awt.image.*;
import javax.imageio.*;
public class CoinCounter {
public static void main(String[] args) throws Exception {
ImageIO.setUseCache(false);
BufferedImage img = ImageIO.read(System.in);
byte[] pixels = ((DataBufferByte) img.getRaster().getDataBuffer()).getData();
int[] pixels2 = new int[3000000];
int kernelPad = 5;
int ones = 0;
int fives = 0;
int tens = 0;
int r, g, b, n;
double x, y, y2;
final double M1 = -0.59;
final double N1 = 1.572;
final double M2 = -110/3.0;
final double N2 = 37.0;
final double M3 = -80/3.0;
final double N3 = 32.0;
for (int i = 0; i < 3000000; i++) pixels2[i] = (256+pixels[i])%256;
for (int i = 0; i < 1000; i++) {
for (int j = 0; j < 1000; j++) {
n = 0;
r = 0;
g = 0;
b = 0;
for (int di = Math.max(0,i-kernelPad); di <= Math.min(999, i+kernelPad); di++) {
for (int dj = Math.max(0,j-kernelPad); dj <= Math.min(999, j+kernelPad); dj++) {
r += pixels2[3000*dj+3*di];
g += pixels2[3000*dj+3*di+1];
b += pixels2[3000*dj+3*di+2];
n++;
}
}
r /= n;
g /= n;
b /= n;
// System.out.println(r + " " + g + " " + b);
if (r + g + b >= 600) continue;
x = ((double) r)/b;
y = ((double) b)/g;
y2 = b-g;
if (y >= M1*x + N1) ones++;
else if ((x <= 0.5 && y2 <= M2*x + N2) || (x > 0.5 && y2 <= M3*x + N3)) fives++;
else tens++;
}
}
long ones2;
if (fives == 0 && tens > 100) {
ones += 4*tens;
ones2 = Math.round(ones/3612.5);
} else {
ones2 = Math.round(((double) ones + 0.014*tens)/3612.5);
if (fives < 95000) fives -= 3600;
}
long fives2 = Math.round((Math.max(fives, 0) + 0.004*tens)/3544.5);
long tens2 = Math.round(Math.round(tens - 0.0005*fives)/4105.0);
System.out.println(ones2 + 5*fives2 + 10*tens2);
}
}