OPPO-多媒体C++-提前批笔试
笔试-2023年7月20日
经典觉得很简单,完全不知道为什么a不了的题目。
- 构造一个二阶行列式,使得其计算的值为给出的x. 给出x,最快速找出一个ad-bc=x. 要求:a、b、c、d不能超过20,且均为正整数。
- 题目实现。这不就是模拟吗,有什么情况。
- 题目实现,广度搜索。答案错误。人麻了
回合制攻击。给出回合数n,基础攻击力a,连击伤害b 每轮回合,攻击BOSS一次,BOSS攻击我一次。 每次攻击BOSS,增加一次连击。攻击boss伤害为:a+连击次数*b 每次攻击我,可能发生闪避。如果闪避失败,连击次数清零。 给出n,a,b,以及使用o、x表示每回合我是否闪避的字符串,o代表闪避,x代表失败,求最终攻击的总伤害。
int main()
{
int n, a, b;
string s;
cin >> n >> a >> b >> s;
int damage = 0;
int combo = 0;
for (int i = 0; i < n; i++)
{
// 先进行攻击
damage += a + combo * b;
// 然后判断闪避
if (s[i] == 'x')
{
combo = 0;
}
else
{
combo++;
}
}
cout << damage << endl;
return 0;
}
初始位置在x,y,每一步可前往: 1、(x+k, y+k),k为任意整数 2. (x+k, y-k),k为任意整数 3. (x+a, y+b),|a|+|b|=3,|a| |b|在1和2之间。一共有8种可能。a为+-1,b为+-2,或者a为+-2,b为+-1 给出t组初始位置x1,y1,和目标位置x2,y2,求每组从初始位置前往目标位置的最少步数
int canJump(int ndx, int ndy)
{
// 如果跳到了目标点,那么就只需要一步
if (ndx == 0 && ndy == 0)
{
return 0;
}
// 如果跳到了对角线上,那么就只需要两步
if (ndx == ndy || ndx == -ndy)
{
return 1;
}
return -1;
}
int main()
{
vector<pair<int, int>> ab = {{1, 2}, {1, -2}, {-1, 2}, {-1, -2}, {2, 1}, {2, -1}, {-2, 1}, {-2, -1}};
vector<int> res;
int t;
cin >> t;
while (t--)
{
int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
int dx = x2 - x1;
int dy = y2 - y1;
int step = canJump(dx, dy);
if (step >= 0)
{
res.push_back(step);
continue;
}
// 其他情况,就先使用(a,b),跳往周围的8个点,
// 广度优先遍历,直到找到目标点
queue<pair<int, int>> q;
q.push(make_pair(x1, y1));
// 记录已经访问过的点
unordered_map<int, unordered_map<int, bool>> visited; // visited[x][y] = true
visited[x1][y1] = true;
step = 0;
bool ok = false;
while (!q.empty())
{
int size = q.size();
while (size--)
{
auto p = q.front();
q.pop();
for (auto &i : ab)
{
int ndx = p.first + i.first;
int ndy = p.second + i.second;
if (visited[ndx][ndy])
{
continue;
}
int canJumpStep = canJump(ndx - x2, ndy - y2);
if (canJumpStep >= 0)
{
res.push_back(step + canJumpStep + 1);
ok = true; // 找到了
break;
}
visited[ndx][ndy] = true;
q.push(make_pair(ndx, ndy));
}
if (ok)
{
break;
}
}
if (ok)
{
break;
}
step++;
}
}
for (auto i : res)
cout << i << endl;
return 0;
}

查看14道真题和解析