【NOIP2016提高组复赛】玩具谜题

来源:互联网 发布:朔州seo搜索优化 编辑:程序博客网 时间:2024/05/04 08:26

Description

这里写图片描述

Solution

这就是一道模拟题吗。
向右就加,然后mod一下。向左就减,然后mod一下。

Code

#include<iostream>#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>#define fo(i,a,b) for(i=a;i<=b;i++)#define fod(i,a,b) for(i=a;i>=b;i--)#define rep(i,a) for(i=first[a];i;i=next[i])using namespace std;typedef long long ll;const int maxn=100007,mo=1e9+7;int i,j,k,l,t,n,m,ans;int a[maxn];char s[maxn][51];int main(){    freopen("toy.in","r",stdin);    freopen("toy.out","w",stdout);    scanf("%d%d",&n,&m);    fo(i,0,n-1){        scanf("%d%s",&a[i],s[i]);    }    t=0;    fo(i,1,m){        scanf("%d%d",&k,&l);        if(a[t]){            if(k){                t=((t-l)%n+n)%n;            }            else{                t=(t+l)%n;            }        }        else{            if(k){                t=(t+l)%n;                }            else{                t=((t-l)%n+n)%n;            }        }    }    ans=strlen(s[t]);    fo(i,0,ans)putchar(s[t][i]);    return 0;}
1 0