#include <bits/stdc++.h>
using namespace std;
struct ch{
string name;
int heading;
};
struct cmd{
int heading;
int value;
};
ch arr[100001];//朝向+人物
cmd u[100001];//命令
int ans;
void dfs(int dfs_num, int start_pos, int ch_num, int com_num){
if(dfs_num == com_num + 1){
return;
} else {
int hd = u[dfs_num].heading;
int val = u[dfs_num].value;//要走多少步
int end_pos;
if(hd == 1){
if(arr[start_pos].heading == 1){
if(start_pos - val < 0){
end_pos = start_pos + ch_num - val;
} else {
end_pos = start_pos - val;
}
} else if(arr[start_pos].heading == 0){
if(start_pos + val > ch_num){
end_pos = start_pos + val - ch_num;
} else {
end_pos = start_pos + val;
}
}
} else if(hd == 0){
if(arr[start_pos].heading == 0){
if(start_pos - val < 0){
end_pos = start_pos + ch_num - val;
} else {
end_pos = start_pos - val;
}
} else if(arr[start_pos].heading == 1){
if(start_pos + val > ch_num){
end_pos = start_pos + val - ch_num;
} else {
end_pos = start_pos + val;
}
}
}
ans = end_pos;
dfs(dfs_num + 1, end_pos, ch_num, com_num);
}
}
int main(){
int ch_num, com_num;
cin >> ch_num >> com_num;
for(int i = 1; i <= ch_num; i++){
cin >> arr[i].heading >> arr[i].name;
}
for(int i = 1; i <= com_num; i++){
cin >> u[i].heading >> u[i].value;
}
dfs(1, 1, ch_num, com_num);
cout << arr[ans].name;
return 0;
}
递归,有没有大佬帮帮我(哭)