LUOGU 洛谷 P1563 玩具谜题

问题 https://www.luogu.org/problemnew/show/P1563

这是一道简单的模拟类型的题,主要注意两点

  1. 数据量有点大,int无法表示,用long才能100%AC
  2. 朝外向左与朝内向右是一样的方向,反之亦然,因此模拟判断过程可以稍微简化
#include <stdio.h>

#define MAX_N 100000
#define MAX_M 100000

int main()
{
    char er_dir[MAX_N] = {0};
    long n, m, i, cur = 0, a, s;
    char er_occ[MAX_N][11] = {{0}};
    scanf("%ld%ld", &n, &m);
    for (i = 0; i < n; ++i) {
        scanf("%ld%s", er_dir+i, er_occ[i]);
    }
    for (i = 0; i < m; ++i) {
        scanf("%ld%ld", &a, &s);
        if (er_dir[cur] == a)// 向外朝左与向内朝右是一致的,反之亦然
        {
            s *= -1;
        }
        cur = (cur + n + s) % n;
    }
    printf("%s", er_occ[cur]);
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_23937195/article/details/79637065
今日推荐