望前辈提点提点orz
问题应该是出在处理数组头尾衔接上,大家都用取余,我觉得我处理的和取余应该是一样的,但是却没全对,我换成最高赞题解的取余形式就全对了,想知道这两种有什么不一样的。
拜托了诸位orz
#include <iostream>
#include <string>
using namespace std;
struct sa
{
int cx;
string name;
}ppl[100000];
int main()
{
int n, m;
cin >> n >> m;
for (int i = 0; i < n; ++i)
{
cin >> ppl[i].cx >> ppl[i].name;
}
int ansi=0;
for (int i = 0; i < m; ++i)
{
int fx, ws;
cin >> fx >> ws;
if (ppl[ansi].cx == 0 && fx == 0)ansi -= ws;
if (ppl[ansi].cx == 0 && fx == 1)ansi += ws;
if (ppl[ansi].cx == 1 && fx == 0)ansi += ws;
if (ppl[ansi].cx == 1 && fx == 1)ansi -= ws;
if (ansi >= n)ansi -= n;
if (ansi <= -1)ansi += n;
}
cout << ppl[ansi].name << endl;
}