P1563 [NOIP2016 提高组] 玩具谜题
题目链接
题目思路
当谜题方向与小人朝向相同时是逆时针,相反时是顺时针,求最终小人位置
题目代码
#include <iostream>
#include <algorithm>
using namespace std;
typedef pair<int, string> PIS;
const int N = 100010;
PIS toy[N];
int n, m;
int main()
{
cin >> n >> m;
for(int i = 1; i <= n; i ++ )
{
int x;
string a;
cin >> x >> a;
toy[i] = {x, a};
}
int ans = 1;
while(m -- )
{
int d, c;
cin >> d >> c;
if(d == toy[ans].first)
ans -= c;
else ans += c;
if(ans <= 0) ans += n;
if(ans > n) ans -= n;
}
cout << toy[ans].second << endl;
return 0;
}
孤独本是常态

浙公网安备 33010602011771号