题解: 四种情况(具体两种),即顺时针还是逆时针;以防止b太大,我用了while循环,(题目好像 b 并不大);
参考代码1.0: res从1开始的。。。
#include<queue>#include<cstdio>#include<string>#include<cstring>#include<iostream>#include<algorithm>#define INF 0x3f3f3f3f#define MAX 20010usingnamespace std;int N, M, a, b, res =1;int dir[100010];
string str[100010];intmain(){
cin >> N >> M;for(int i =1; i <= N; i++) cin >> dir[i]>> str[i];for(int i =0; i < M; i++){
cin >> a >> b;int t = res;if(a ==0)// 左{if(dir[t]==0)//朝内{
res -= b;while(res <=0) res += N;}else//朝内{
res += b;while(res > N) res -= N;}}else//右{if(dir[t]==0)//朝内{
res += b;while(res > N) res -= N;}else//朝内{
res -= b;while(res <=0) res += N;}}}
cout << str[res];return0;}
#include<queue>#include<cstdio>#include<string>#include<cstring>#include<iostream>#include<algorithm>#define INF 0x3f3f3f3f#define MAX 20010usingnamespace std;int N, M, a, b, res;int dir[100010];
string str[100010];intmain(){
cin >> N >> M;for(int i =0; i < N; i++) cin >> dir[i]>> str[i];for(int i =0; i < M; i++){
cin >> a >> b;//左 朝内if(a ==0&& dir[res]==0) res =(res + N - b)% N;elseif(a ==0&& dir[res]==1) res =(res + b)% N;elseif(a ==1&& dir[res]==0) res =(res + b)% N;elseif(a ==1&& dir[res]==1) res =(res + N - b)% N;}
cout << str[res];return0;}