洛谷P1563 [NOIP2016 提高组] 玩具谜题进阶解法

#include<cstdio>
#include<cstdlib>
struct Man
{
	int f1;
	int f2;
	int s;
	char g[10];
};
int main(void)
{
	int i,j,k,N, M;
	Man* p=(Man*)malloc(sizeof(Man)*100000);
	scanf("%d%d", &N, &M);
	for (i = 0; i < N; i++)
		scanf("%d%s", &(p + i)->f1, (p + i)->g);
	for (i=0,j=0;j<M;j++)
	{
		scanf("%d%d", &(p+i)->f2, &(p+i)->s);
		k = (p+i)->s;
		if ((p+i)->f1 != (p+i)->f2)
			i = (i+(*(p + i)).s) % N;
		else
			i = (i+N-(*(p + i)).s) % N;
	}
	printf("%s",(p+i)->g);
	free(p);
	return 0;
}
上一篇:man命令笔记


下一篇:Redis与epoll