题解:P1563 [NOIP2016 提高组] 玩具谜题
solution
一道小模拟。
对于一个人
- 若
A_i=0 ,即朝内,向左找就减,向右找就加。 - 若
A_i=1 ,即朝外,向左找就加,向右找就减。
对于一组询问
加减后再对
code
#include <bits/stdc++.h>
using namespace std;
int n, m, a[100005], now=1;
string b[100005];
int main () {
cin >> n >> m;
for (int i=1; i<=n; ++i)
cin >> a[i] >> b[i];
for (int x, s; m--; )
cin >> x >> s,
now=(now+(a[now]==x?-s:s)+n)%n,
now=(!now?n:now);
cout << b[now];
return 0;
}