乐狗游戏笔试

乐狗游戏2023届秋季招聘笔试-游戏服务器开发

编程题1==AC==

image-20220820200205723

image-20220820200217061

image-20220820200225355

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
public class Solution {
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
* 输入参数 Ax 角色A的血量,Ay 角色A 的攻击力,Az A的攻击CD,Aw 角色A的恢复力
输入参数 Bx 角色B的血量,By 角色B 的攻击力,Bz B的攻击CD,Bw 角色B的恢复力
* @param Ax int整型 角色A的血量上限
* @param Ay int整型 角色A的攻击力
* @param Az int整型 A的攻击CD
* @param Aw int整型 角色A的每回合恢复血量值
* @param Bx int整型 角色B的血量上限
* @param By int整型 角色B的攻击力
* @param Bz int整型 B的攻击CD
* @param Bw int整型 角色B的每回合恢复血量值
* @return int整型
*/
public int PK (int Ax, int Ay, int Az, int Aw, int Bx, int By, int Bz, int Bw) {
// write code here
if (Ax > By && (Az + 1) * Aw >= By && Bx > Ay && (Bz + 1) * Bw >= Ay)
return 4;
int ax = Ax, bx = Bx;
int cnt = 0;
while(ax > 0 && bx > 0) {
ax = Math.min(Ax, ax + Aw);
bx = Math.min(Bx, bx + Bw);
if (cnt % (Az + 1) == 0)
bx -= Ay;
if (cnt % (Bz + 1) == 0)
ax -= By;
cnt++;
}

if (ax > 0 && bx <= 0)
return 1;
else if (ax <= 0 && bx >0)
return 2;
else
return 3;
}
}

image-20220820212914615

编程题2

image-20220820203403864

image-20220820203417410

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import java.util.*;

public class Solution {
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
* 给定字符串 和 显示宽度。 按规则返回自动换行处理后的最后一行。 如不能则返回字符串"error"
* @param str string字符串 给定的字符串
* @param width int整型 显示的宽度
* @return string字符串
*/
public String getLastLine (String str, int width) {
// write code here
String[] strs = str.split(" ");
String ans = "";
for (String temp : strs) {
if (temp.length() * 16 > width)
return "error";
else if (temp != "" && temp != null)
ans = temp;
}
return ans;
}
}

image-20220820204401842

这道题完全不知道怎么做,随便写了个,混了些测试案例

编程题3

image-20220820204431428

image-20220820204442687

image-20220820204451090

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
public class Solution {

int ans = -1;
int[][] directions = new int[][]{{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
* 抵达铁门时可能的最大生命值,如果不可达,则返回 -1。
* @param cave int整型二维数组 洞穴的信息
* @param hp int整型 小明的初始生命值
* @return int整型
*/
public int EscapeFromCave (int[][] cave, int hp) {
// write code here
int x = 0, y = 0;
for (int i = 0; i < cave.length; i++) {
for (int j = 0; j < cave[0].length; j++)
if (cave[i][j] == -2) {
x = i;
y = j;
break;
}
if ( x != 0 && y != 0)
break;
}
boolean[][] visited = new boolean[cave.length][cave[0].length];
visited[x][y] = true;
dfs(cave, x, y, hp, visited);
return ans;
}

public void dfs(int[][] cave, int curi, int curj, int hp, boolean[][] visited) {
if (hp <= 0)
return ;
if (cave[curi][curj] == -3) {
ans = Math.max(ans, hp - 3);
return ;
}

for (int[] dir : directions) {
int tempi = curi + dir[0], tempj = curj + dir[1];
if (tempi < 0 || tempi >= cave.length || tempj < 0 || tempj >= cave[0].length || cave[tempi][tempj] == -1 || visited[tempi][tempj])
continue;
visited[tempi][tempj] = true;
dfs(cave, tempi, tempj, hp - cave[tempi][tempj], visited);
}
}
}

image-20220820211601421

还是有一个特殊的案例没过,不知道为啥


乐狗游戏2023届秋季招聘笔试-游戏服务器开发
http://example.com/2022/08/20/笔试记录/乐狗游戏2023届秋季招聘笔试-游戏服务器开发/
作者
madao33
发布于
August 20, 2022
许可协议