forked from RiviereGregory/CodinGame
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Ragnarök - Thor contre les Géants.txt
128 lines (107 loc) · 3.69 KB
/
Ragnarök - Thor contre les Géants.txt
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import java.util.*;
import java.io.*;
import java.math.*;
class Player {
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
int thorX = in.nextInt();
int thorY = in.nextInt();
int nbCoups;
int nbGeant;
while (true) {
nbCoups = in.nextInt();
nbGeant = in.nextInt();
int[] geantX = new int[nbGeant];
int[] geantY = new int[nbGeant];
for(int i=0; i< nbGeant ; i++){
geantX[i] = in.nextInt();
geantY[i] = in.nextInt();
}
String choix = actionThor(geantX, geantY, thorX, thorY, nbCoups);
switch(choix){
case "N": thorY -= 1;
break;
case "S": thorY += 1;
break;
case "NE": thorY -= 1;
thorX +=1 ;
break;
case "SE": thorY += 1;
thorX +=1 ;
break;
case "NW": thorY -= 1;
thorX -=1 ;
break;
case "SW": thorY += 1;
thorX -=1 ;
break;
case "E": thorX +=1 ;
break;
case "W": thorX -=1 ;
break;
}
// Write action to standard output
System.out.println(choix );
}
}
public static String actionThor(int[] geantX, int[] geantY,int thorX,int thorY, int nbCoups){
String dir = "";
int nbGeantPorte = 0;
int nbGeant = geantX.length;
int[] X = new int[nbGeant];
int[] Y = new int[nbGeant];
int[] indiceGeant = new int[nbGeant];
if(nbGeant < nbCoups){
for(int i =0; i<nbGeant; i++){
X[i] = geantX[i] - thorX;
Y[i] = geantY[i] - thorY;
if((Math.abs(X[i]) >0 && Math.abs(X[i])<3) || (Math.abs(Y[i]) >0 && Math.abs(Y[i])<3)){
dir = "STRIKE";
break;
}
}
}else{
for(int i =0; i<nbGeant; i++){
indiceGeant[0] = 0;
X[i] = geantX[i] - thorX;
Y[i] = geantY[i] - thorY;
if((Math.abs(X[i]) > 0 && Math.abs(X[i])<3) || (Math.abs(Y[i]) >0 && Math.abs(Y[i])<3)){
nbGeantPorte++;
}else{
if(Math.abs(X[i]) >Math.abs(Y[i]) ){
indiceGeant[i] = X[i];
}else{
indiceGeant[i] = Y[i];
}
}
}
int max = indiceGeant[0];
int indice =0;
if(nbGeantPorte<nbGeant){
for(int i =1; i<nbGeant; i++){
if(indiceGeant[i]>max){
max = indiceGeant[i];
indice = i;
}
}
if(Y[indice]>0){
dir +="S";
}else if(Y[indice]<0){
dir +="N";
}
if(X[indice]>0){
dir +="E";
}else if(X[indice]<0){
dir +="W";
}
}else{
dir = "STRIKE";
}
}
if("".equalsIgnoreCase(dir)){
dir = "WAIT";
}
//System.out.println(dir);
return dir;
}
}