洛谷 P1563. [NOIP2016 提高组] 玩具谜题
原题链接
简单
作者:
JY_ZKY
,
2023-02-13 21:21:20
,
所有人可见
,
阅读 109
循环模拟
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 1e5 + 10;
typedef long long LL;
struct Node
{
int id;
string name;
}nodes[N];
int main()
{
LL n,m;
cin >> n >> m;
for(int i = 0; i < n ; i ++) cin >> nodes[i].id >> nodes[i].name;//0朝内、1朝外
LL now = 0;
while (m -- )
{
LL dir ,r;
cin >> dir >> r;
//向内右手边、向外左手边就是逆时针
if(nodes[now].id == 0 && dir == 0) now = (now - r + n) % n;
else if(nodes[now].id == 0 && dir == 1) now = (now + r) % n;
else if(nodes[now].id == 1 && dir == 0) now = (now + r) % n;
else now = (now - r + n) % n;
}
cout << nodes[now].name << endl;
return 0;
}