2016D1T1 玩具迷题
problem&solution
注意下标从0开始,否则模的时候会出现5%5=0这类情况。异或会使得特判少很多。
code
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
using namespace std;
int read(){
int a=0,op=1;char c=getchar();
while(c>'9'||c<'0') {if(c=='-') op=-1;c=getchar();}
while(c>='0'&&c<='9'){a*=10,a+=c^48,c=getchar();}
return a*op;
}
const int maxn=1e5+10;
int n,m;
char s[maxn][20];
int pos[maxn];//0 nei 1 wai
int main(){
n=read(),m=read();
for(int i=0;i<n;i++) scanf("%d %s",&pos[i],s[i]);
int cur=0;
for(int i=1;i<=m;i++){
int a,b;
a=read(),b=read();//0 left 1 right
if(a^pos[cur]==1) cur=(cur+b)%n;
else cur=((cur-b)%n+n)%n;
}
printf("%s",s[cur]);
return 0;
}