NOIP2016 day1 T1 玩具谜题 toy 题解

NOIP2016 day1 T1 玩具谜题 toy 题解_第1张图片
NOIP2016 day1 T1 玩具谜题 toy 题解_第2张图片
NOIP2016 day1 T1 玩具谜题 toy 题解_第3张图片
NOIP2016 day1 T1 玩具谜题 toy 题解_第4张图片

题目如上描述,思路是如果小人的朝向与查询的方向相同就减,不同就加,然后直接模拟。
毕竟是day1T1还比较简单。
附AC代码:

#include
#include
#include
#include
#include
#include
#include
#include

using namespace std;

const int maxn = 1e5+5;
int n,m;
int dic,len;
int tws[maxn];
char mz[maxn][15];

template <class T> inline void read(T &xx)
{
    xx = 0;
    T flag = 1;
    char ch = (char)getchar();
    while(ch<'0' || ch>'9')
    {
        if(ch == '-') flag = -1;
        ch = (char)getchar();
    }
    while(ch>='0' && ch<='9')
    {
        xx = (xx<<1) + (xx<<3) + ch - '0';
        ch = (char)getchar();
    }
    xx *= flag;
}

int main()
{
    freopen("toy.in","r",stdin);
    freopen("toy.out","w",stdout);
    int now = 1,len;
    read(n); read(m);
    for(int i = 1; i <= n; i++)
    {
        read(tws[i]);
        scanf("%s",mz[i]);
    }
    while(m--)
    {
        read(dic); read(len);
        if(dic == tws[now])
        {
            if(now > len) now -= len;
            else now = n-len+now;
        }
        else if(dic != tws[now])
        {
            if(now+len > n) now = len+now-n;
            else now = len+now;
        }
    }
    for(int i = 0; i < strlen(mz[now]); i++)
        printf("%c",mz[now][i]);
    return 0;
}

你可能感兴趣的:(NOIP2016,NOIP2016,提高组,DAY1,T1,模拟)