#include<iostream>
#include<cstdio>
#include <iomanip>
#include<cmath>
#include<string>
#include<algorithm>
using namespace std;
//有点像循环队列,关键是移动的时候不能简单加减,要使用模运算来移动
struct student {
int flag;//朝内还是朝外
char name[20];
}stu[500000];
struct order {
int direction;
int number;
}ord[500000];
int main()
{
//student stu[100];
int n, m;
cin >> n>>m;
for (int i = 0; i < n; i++)
cin >> stu[i].flag >> stu[i].name;
//order ord[100];
for (int j = 0; j < m; j++)
cin >> ord[j].direction >> ord[j].number;
int b = 0;
for (int k = 0; k < m; k++)
{
if (stu[b].flag == 0)
{
if (ord[k].direction == 1)//往右
{
b = (b+ ord[k].number) % n;
}
else//往左
{
b = (b + (n - ord[k].number)) % n;//要用%运算符,不是简单的相减,有点像队列
}//简单的相加会超出
}
else
{
if (ord[k].direction == 1)//往右
{
b = (b+(n- ord[k].number) ) % n;
}
else//向左
{
b = (b + ord[k].number) % n;
}
}
}
cout << stu[b].name;
return 0;
}
P1563玩具谜题(C++)
最新推荐文章于 2024-03-31 17:18:59 发布