20241002每日一题洛谷P1563

粗看题目
我靠,什么方向还变来变去的(哭泣
核心思想:圈内右数,圈外左数为整体逆时针数;圈外右数,圈内左数为整体顺时针数
运用结构体就有了第一版源码:

struct people
{
	int face;
	char name[12];
};
int main() {
	int m, n;
	scanf("%d %d", &n, &m);
	people a[10010];
	for (int i = 0; i < n; i++) {
		scanf("%d %s", &a[i].face, &a[i].name);
	}
	int lr, num;
	int point = 0;
	for (int i = 0; i < m; i++) {
		scanf("%d %d", &lr, &num);
		if ((a[point].face + lr) % 2 == 1) {//定义圈内右数,圈外左数为整体逆时针数
			point += num;
			if (point > n) {
				point -= n;
			}
		}
		else//圈外右数,圈内左数为整体顺时针数
		{
			point -= num;
			if (point < 0) {
				point += n;
			}
		}
	}
	printf("%s", a[point].name);
	return 0;
	
}

/////

第一次提交:坏消息,5个RE,2个WA
于是乎回顾题目,发觉n和m为1e5,原来是数组开小了
把数组开在全局,以及将
if (point 0)
单次判断改写为
while (point 0)一直判断

/////

第二次提交:坏消息,2个WA任然错误
经过老登指导,发现转圈的时候是以1为起点
if (point > n) {
point -= n;
}
改写为
if (point >= n)

/////

第三次提交:成功解决问题AC了!!!
AC代码:

struct people
{
	int face;
	char name[12];
};
people a[100010];
int main() {
	int m, n;
	scanf("%d %d", &n, &m);
	for (int i = 0; i < n; i++) {
		scanf("%d %s", &a[i].face, &a[i].name);
	}
	int lr, num;
	int point = 0;//指针
	for (int i = 0; i < m; i++) {
		scanf("%d %d", &lr, &num);
		if ((a[point].face + lr) % 2 == 1) {//定义圈内右数,圈外左数为整体逆时针数
			point += num;
			while(point >= n) {
				point -= n;
			}
		}
		else//圈外右数,圈内左数为整体顺时针数
		{
			point -= num;
			while (point < 0) {
				point += n;
			}
		}
	}
	printf("%s", a[point].name);
	return 0;
}
posted @ 2024-10-06 10:30  才瓯  阅读(8)  评论(0)    收藏  举报