基础模拟
位置运算 可以模掉无效值
注意细节即可
#include <iostream>
using namespace std;
const int MAXN = 1e5 + 10;
int pep[MAXN];
string name[MAXN];
int n, m;
int pos(int rit, int f, int mode)
{
f %= n;
if(mode == 1)
{
if(rit - f < 0)
{
f -= rit;
rit = n - f;
}
else
rit = rit - f;
}
else
{
if(rit + f >= n)
{
f -= n - rit;
rit = f;
}
else
{
rit = rit + f;
}
}
return rit;
}
int main()
{
ios::sync_with_stdio(false);
cin>>n>>m;
for(int i = 0; i < n; i++)
{
cin>>pep[i];
cin>>name[i];
}
int flag = 0;
int ta, tb;
while(m--)
{
cin>>ta>>tb;
if(pep[flag] == 0)
{
if(ta == 0)
{
flag = pos(flag, tb, 1);
}
else
{
flag = pos(flag, tb, 0);
}
}
else
{
if(ta == 0)
{
flag = pos(flag, tb, 0);
}
else
{
flag = pos(flag, tb, 1);
}
}
}
cout<<name[flag]<<endl;
return 0;
}