题解 | #[NOIP2016]玩具谜题#

[NOIP2016]玩具谜题

https://ac.nowcoder.com/acm/problem/16426

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
using namespace std;
const int N = 1e5 + 10;
int direction[N];
string name[N];
int n, m, ans = 0;

int solution(int x, int y)
{
	if (direction[ans] == 0) //朝内
	{
		if (x == 0)//左边
		{
			ans = (ans - y + n) % n;
		}
		else
		{
			ans = (ans + y) % n;
		}
	}
	else //朝外
	{
		if (x == 0)//左边
		{
			ans = (ans + y) % n;
		}
		else
		{
			ans = (ans - y + n) % n;
		}
	}
	return ans;
}

int main() {
	cin >> n >> m;
	for (int i = 0; i < n; i++)
		cin >> direction[i] >> name[i];

	for(int i=1;i<=m;i++)
	{
		int a, s;
		cin >> a >> s;
		ans = solution(a, s);
	}
	cout << name[ans] << endl;
	return 0;
}
全部评论

相关推荐

Rena1ssanc...:对的,要是面评没太烂,勤更新简历等捞就行了,腾讯可以无限复活
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务