题目
https://www.luogu.com.cn/problem/P1563
代码
#include<iostream> #include<string> #include<cstring> #include<cstdio> using namespace std; struct node { int towards; string name; }list[100005]; int n, m; int main() { std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0); cin >> n >> m; for (int i = 0; i < n; i++) { cin >> list[i].towards >> list[i].name; } int num = 0; for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; if (a == 0) { if (list[num].towards == 0)num = ((num - b) % n + n) % n; else num = ((num + b) % n + n) % n; } else { if (list[num].towards == 0)num = ((num + b) % n + n) % n; else num = ((num - b) % n + n) % n; } } cout << list[num].name << endl; }