Hey guys, can anybody tell me what I am missing? I tried some variations of my code but always seem to be short by 1 round for test 6 and 7. Here is my code:
Auto-generated code below aims at helping you parse
the standard input according to the problem statement.
**/
class Player {
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
int W = in.nextInt(); // width of the building.
int H = in.nextInt(); // height of the building.
int N = in.nextInt(); // maximum number of turns before game over.
int X0 = in.nextInt();
int Y0 = in.nextInt();
int x = X0;
int y = Y0;
int x1 = W/2;
int y1 = H/2;
String batDir = "";
String curDir = "";
// game loop
while (true) {
String bombDir = in.next(); // the direction of the bombs from batman's current location (U, UR, R, DR, D, DL, L or UL)
switch(bombDir)
{
case "U":
y = y - y1;
x = x + 0;
break;
case "UR":
y = y - y1;
x = x + x1;
break;
case "R":
y = y + 0;
x = x + x1;
break;
case "DR":
y = y + y1;
x = x + x1;
break;
case "D":
y = y + y1;
x = x + 0;
break;
case "DL":
y = y + y1;
x = x - x1;
break;
case "L":
y = y + 0;
x = x - x1;
break;
case "UL":
y = y - y1;
x = x - x1;
break;
}
// Write an action using System.out.println()
// To debug: System.err.println("Debug messages...");
//To close in on bomb position
if(!curDir.equals(bombDir))
{
x1 = Math.round(x1/2);
y1 = Math.round(y1/2);
if(x1 < 1)
{
x1 = 1;
y1 = 1;
}
}
//To stay in bounds
if (y > H - 1)
{
y = H - 1;
}
if (y < 0)
{
y = 0;
}
if (x > W - 1)
{
x = W - 1;
}
if (x < 0)
{
x = 0;
}
curDir = bombDir;
batDir = x + " " + y;
System.out.println(batDir);
}
Reading the console output as a whole will give you some insight where your code may go wrong. Take Case 6 for example:
Locate the bombs, save the hostages! Batman is on window (5,98) The bombs are located above and to the left of Batman
### Standard Output Stream:
0 48
Batman moved from window (5,98) to window (0,48) The bombs are located above Batman
### Standard Output Stream:
0 23
Batman moved from window (0,48) to window (0,23) The bombs are located above Batman
### Standard Output Stream:
0 11
Batman moved from window (0,23) to window (0,11) The bombs are located above Batman
### Standard Output Stream:
0 0
Batman moved from window (0,11) to window (0,0) The bombs are located below Batman
### Standard Output Stream:
0 12
Batman moved from window (0,0) to window (0,12) The bombs are located above Batman
### Standard Output Stream:
0 6
Batman moved from window (0,12) to window (0,6) The bombs are located above Batman
### Standard Output Stream:
0 3
Failure: you are too late. Joker's bombs exploded. The hostages are dead. You lose :( Batman moved from window (0,6) to window (0,3) The bombs are located above Batman
Notice that when Batman moved to (0, 11), the feedback was that the bombs are located above (i.e. the Y-coordinate should be between 0 and 10). Yet, in a later turn, your output is (0, 12). That is where you would want to investigate further.
You may probably do a similar investigation for Test 7.
By the way, you may format your code properly on this forum by using the </> button in the formatting toolbar.
One final validator is bugged or a hidden edge case: the Lesser jumps one with bomb at 6,6 and batman at 38,38.
Batman does not get a chance to move at all, game ends at round 1.
/bin/bash: /opt/coderunner/dotnet/cg/csharp/build_debug.sh: No such file or directory
Timeout: your program did not provide an input in due time.
Considering that my program either runs and wins or does not run at all I think the C# time limits are insufficient or they measure .NET startup time too.
The points is not to win, just to answer “0 0” in time. Which it can fail to do, e.g. in my latest Tower test result batman stays at [0,42] and turns don’t tick. Unlike Lesser jumps where turns tick and batman moves.
Now I dare you to optimize that code for speed
That shouldn’t be the case. I’ve written the solution codes in all the programming languages offered by CG and don’t encounter any particular issues like yours.
Maybe it’s this puzzle’s time limits. Or inefficient dotnet startup.
Can you submit a working C# solution to this puzzle 5 times to cycle through all the final test cases? Will you get 100% all the time or just most of the time?
Hello, can you help me? I have encountered a problem. I wrote it in C language and now I reported an error in the sixth and seventh test programs during testing. I have been modifying it all night. Could you please help me take a look? Thank you
Auto-generated code below aims at helping you parse
the standard input according to the problem statement.
**/
int main()
{
// width of the building.
int W;
// height of the building.
int H;
scanf(“%d%d”, &W, &H);
// maximum number of turns before game over.
int N;
scanf(“%d”, &N);
int X0;
int Y0;
double lsx,lsy;
scanf(“%d%d”, &X0, &Y0);
lsx=W/4;
lsy=H/4;
int zsy;
int zsx;
if(lsx>X0&&lsy<Y0)
{lsx=X0/2.0;
lsy=Y0/2.0;
}
// game loop
while (1) {
// the direction of the bombs from batman’s current location (U, UR, R, DR, D, DL, L or UL)
char bomb_dir[4];
scanf(“%s”, bomb_dir);
if(strcmp(bomb_dir,“U”)==0)
{
Y0-=lsy;
lsy=lsy/2.0;
zsy=lsy;
if(lsy*10-zsy>=5)lsy+=0.5;
}
if(strcmp(bomb_dir,“UR”)==0)
{
X0+=lsx;
Y0-=lsy;
lsx=lsx/2.0;
lsy=lsy/2.0;
zsy=lsy;
zsx=lsx;
if(lsy*10-zsy>=5)lsy+=0.5;
if(lsx*10-zsx>=5)lsx+=0.5;
}
if(strcmp(bomb_dir,"R")==0)
{
X0+=lsx;
lsx=lsx/2.0;
zsx=lsx;
if(lsx*10-zsx>=5)lsx+=0.5;
}
if(strcmp(bomb_dir,"DR")==0)
{
X0+=lsx;
Y0+=lsy;
lsx=lsx/2.0;
lsy=lsy/2.0;
zsy=lsy;
zsx=lsx;
if(lsy*10-zsy>=5)lsy+=0.5;
if(lsx*10-zsx>=5)lsx+=0.5;
}
if(strcmp(bomb_dir,"D")==0)
{
Y0+=lsy;
lsy=lsy/2.0;
zsy=lsy;
if(lsy*10-zsy>=5)lsy+=0.5;
}
if(strcmp(bomb_dir,"DL")==0)
{
X0-=lsx;
Y0+=lsy;
lsx=lsx/2.0;
lsy=lsy/2.0;
zsy=lsy;
zsx=lsx;
if(lsy*10-zsy>=5)lsy+=0.5;
if(lsx*10-zsx>=5)lsx+=0.5;
}
if(strcmp(bomb_dir,"L")==0)
{
X0-=lsx;
lsx=lsx/2.0;
zsx=lsx;
if(lsx*10-zsx>=5)lsx+=0.5;
}
if(strcmp(bomb_dir,"UL")==0)
{
X0-=lsx;
Y0-=lsy;
lsx=lsx/2.0;
lsy=lsy/2.0;
zsy=lsy;
zsx=lsx;
if(lsy*10-zsy>=5)lsy+=0.5;
if(lsx*10-zsx>=5)lsx+=0.5;
}
// Write an action using printf(). DON'T FORGET THE TRAILING \n
// To debug: fprintf(stderr, "Debug messages...\n");
// the location of the next window Batman should jump to.z
printf("%d %d\n",X0,Y0);
}
return 0;
At first I cant solve the last one"Not there", then I noticed that someone mentioned about ‘math.ceil()’. So I apply this function to update every loop’s Binary Solution and It worked!!!
**can someone tell me why the bounds get updated in every Condition correctly just not the last one ? **
def calc_step(self, bomb_dir):
x,y = self.pos_x, self.pos_y
if "D" in bomb_dir:
self.lowerbound_height = self.pos_y
y += calcStepSize(self.upperbound_height, self.pos_y)
if "U" in bomb_dir:
self.upperbound_height = self.pos_y
y += calcStepSize(self.lowerbound_height, self.pos_y)
if "R" in bomb_dir:
self.lowerbound_width = self.pos_x
x += calcStepSize(self.upperbound_widht, self.pos_x)
if "L" in bomb_dir:
# THIS GAME CAN GO [or maybe not] STATEMENT
self.upperbound_width = self.pos_x
x += calcStepSize(self.lowerbound_width, self.pos_x)
self.pos_x, self.pos_y = x,y
return [x,y]