-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCCC 00 S4 - Golf.java
42 lines (38 loc) · 1.27 KB
/
CCC 00 S4 - Golf.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
import java.io.*;
import java.util.*;
public class Golf {
static int[] clubs = new int[32];
static int strokes[] = new int [5281];
public static void main(String[] args)throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int D = Integer.parseInt(br.readLine());
int C = Integer.parseInt(br.readLine());
for(int c = 0; c < C;c++){
clubs[c] = Integer.parseInt(br.readLine());
strokes[clubs[c]] = 1;
}
int minStrokes = 999999;
int bestDist = -1;
for(int i = 1; i <= D;i++){
minStrokes = 999999;
bestDist = -1;
if(strokes[i] > 0) continue;
for(int j = 0; j < C;j++){
if(i - clubs[j] >= 1){
if(strokes[i-clubs[j]] != 999999){
if(strokes[i-clubs[j]] < minStrokes){
minStrokes = strokes[i-clubs[j]];
bestDist = i-clubs[j];
}
}
}
}
if(bestDist == -1){
strokes[i] = 999999;
}
else strokes[i] = strokes[bestDist]+1;
//System.out.println("Distance = " + i + " ||| best dist = " + bestDist + " ||| strokes to get to " + i + " = " + strokes[i]);
}
System.out.println(strokes[D] == 999999 ? "Roberta acknowledges defeat." : "Roberta wins in " + strokes[D] + (strokes[D] == 1 ? " stroke." : " strokes."));
}
}