题解:P1563 [NOIP2016 提高组] 玩具谜题

· · 题解

P1563 [NOIP2016 提高组] 玩具谜题

从题目来看,这是道简单的模拟题,只需模拟出小人朝向哪里,来判断他的左手边或右手边是哪边就可以了。

Code

#include <iostream>
using namespace std;
int main(){
    int n,m,t=1;
    cin>>n>>m;
    int turn[n+1];
    string name[n+1];
    for (int i=1;i<=n;i++){
        cin>>turn[i]>>name[i];
    }
    for (int i=1;i<=m;i++){
        int x,y;
        cin>>x>>y;
        if (turn[t]==x){
            t-=y;
        }
        else{
            t+=y;
        }
        if (t<=0){
            t+=n;
        }
        else if(t>n){
            t-=n;
        }
    }
    cout<<name[t];
    return 0;
}