粗看题目
我靠,什么方向还变来变去的(哭泣
核心思想:圈内右数,圈外左数为整体逆时针数;圈外右数,圈内左数为整体顺时针数
运用结构体就有了第一版源码:
/////
define _CRT_SECURE_NO_WARNINGS 1
include <stdio.h>
include
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;//使用point定位结构体
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
单次判断改写为
while (point
/////
第二次提交:坏消息,2个WA任然错误
经过老登指导,发现 转圈的时候是以1为起点
if (point > n) {
point -= n;
}
改写为
if (point >= n)
/////
第三次提交:成功解决问题AC了!!!
AC代码:
/////
define _CRT_SECURE_NO_WARNINGS 1
include <stdio.h>
include
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;
}
/////
标签:左数,洛谷,20241002,point,int,P1563,num,lr,scanf From: https://www.cnblogs.com/dianman/p/18445159