洛谷 P1563 玩具谜题
题目传送门
解题思路:
一道模拟题,如果一个人面向圈内,往左就是减,往右就是加.如果面向圈外,就相反.
AC代码:
1 #include<iostream> 2 #include<cstdio> 3 #include<string> 4 5 using namespace std; 6 7 int n,m,o,a,bj = 1; 8 bool vis[100001]; 9 string s[100001]; 10 11 int main() { 12 scanf("%d%d",&n,&m); 13 for(int i = 1;i <= n; i++) { 14 scanf("%d",&o); 15 cin >> s[i]; 16 if(o == 1) 17 vis[i] = true; 18 else 19 vis[i] = false; 20 } 21 for(int i = 1;i <= m; i++) { 22 scanf("%d%d",&o,&a); 23 if(vis[bj] == 0) 24 if(o == 0) 25 bj = bj - a; 26 else 27 bj = bj + a; 28 else 29 if(o == 0) 30 bj = bj + a; 31 else 32 bj = bj - a; 33 if(bj > n) 34 bj = bj - n; 35 else 36 if(bj < 1) 37 bj = bj + n; 38 } 39 cout << s[bj]; 40 }
//NOIP2016提高 Day1 T1