洛谷P1563 [NOIP 2016 提高组] 玩具谜题 题解

洛谷P1563 [NOIP 2016 提高组] 玩具谜题 题解

题目传送门

思路

这题就是一道简单的小模拟题,唯一需要注意的是序号-1为顺时针数,+1为逆时针数。

代码

#include <bits/stdc++.h>
#define endl '\n'

using namespace std;

const int INF = 0x3f3f3f3f;
const double EPS = 1e-8;
const int N = 1e5 + 5;

// 规定-1为顺时针数,+1为逆时针数

int n, m, ai, si, dir[N][3];
string name[N];

int main() {
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        int d;
        cin >> d;
        cin >> name[i];
        if (d == 0) {
            dir[i][0] = -1;
            dir[i][1] = 1;
        } else {
            dir[i][0] = 1;
            dir[i][1] = -1;
        }
    }
    int cur = 0;
    while (m--) {
        cin >> ai >> si;
        cur = cur + dir[cur][ai] * si;
        if (cur < 0)
            cur += n;
        else if (cur >= n)
            cur %= n;
    }
    cout << name[cur] << endl;
    return 0;
}

AC记录

AC记录,322ms,4.62MB

posted @ 2025-02-13 15:38  2789617221guo  阅读(66)  评论(0)    收藏  举报