题目链接
https://www.luogu.com.cn/problem/P1563
题目分析
既然是环形问题,那么直接取模来进行模拟即可,注意顺时针和逆时针
顺时针的箭头是向左拐,是+
,逆时针的箭头是向右拐,是-
AC代码
// Problem: P1563 [NOIP2016 提高组] 玩具谜题
// Contest: Luogu
// URL: https://www.luogu.com.cn/problem/P1563
// Memory Limit: 500 MB
// Time Limit: 1000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include <iostream>
#define fs first
#define sc second
typedef std::pair<std::string, int> psi;
const int N = 100010;
int n, m;
psi w[N];
// 朝内:左->顺->+,右->逆->-, 0
// 朝外:相反, 1
int main()
{
std::cin >> n >> m;
for (int i = 0; i < n; ++ i)
std::cin >> w[i].sc >> w[i].fs;
// p=0:左数, p=1右数
int p = 0, q = 0, idx = 0;
while (m -- ){
std::cin >> p >> q;
if (!w[idx].sc) // 朝内
if (p) idx = (idx + q) % n;
else idx = (idx + n - q) % n;
else // 朝外
if (p) idx = (idx + n - q) % n;
else idx = (idx + q) % n;
}
std::cout << w[idx].fs;
}
标签:std,NOIP2016,idx,int,P1563,cin,https,刷题
From: https://www.cnblogs.com/ClockParadox43/p/17469599.html