题解
2025-04-15 11:49:50
发布于:江苏
2阅读
0回复
0点赞
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<pair<int, string>> toys(n);
for (int i = 0; i < n; ++i) {
cin >> toys[i].first >> toys[i].second;
}
int current_pos = 0;
for (int i = 0; i < m; ++i) {
int a, s;
cin >> a >> s;
int direction = toys[current_pos].first;
if (direction == 0) {
if (a == 0) {
// 朝内,左数(顺时针)是减
current_pos = (current_pos - s) % n;
if (current_pos < 0) {
current_pos += n;
}
} else {
// 朝内,右数(逆时针)是加
current_pos = (current_pos + s) % n;
}
} else {
if (a == 0) {
// 朝外,左数(逆时针)是加
current_pos = (current_pos + s) % n;
} else {
// 朝外,右数(顺时针)是减
current_pos = (current_pos - s) % n;
if (current_pos < 0) {
current_pos += n;
}
}
}
}
cout << toys[current_pos].second << endl;
return 0;
}
这里空空如也
有帮助,赞一个