Loading

P1563 [NOIP2016 提高组] 玩具谜题

题目链接

https://www.luogu.com.cn/problem/P1563

题目思路

当谜题方向与小人朝向相同时是逆时针,相反时是顺时针,求最终小人位置

题目代码

#include <iostream>
#include <algorithm>

using namespace std;
typedef pair<int, string> PIS;
const int N = 100010;
PIS toy[N];
int n, m;

int main()
{
    cin >> n >> m;
    for(int i = 1; i <= n; i ++ )
    {
        int x;
        string a;
        cin >> x >> a;
        toy[i] = {x, a};
    }
    
    
    int ans = 1;
    while(m -- )
    {
        int d, c;
        cin >> d >> c;
        if(d == toy[ans].first)
            ans -= c;
        else ans += c;
        
        if(ans <= 0) ans += n;
        if(ans > n) ans -= n;
    }
    cout << toy[ans].second << endl;
    return 0;
}
posted @ 2022-03-09 08:30  vacilie  阅读(39)  评论(0)    收藏  举报