文章

11

粉丝

33

获赞

0

访问

2.0k

头像
击鼓传花 题解:
P1018 贵州大学机试题
发布于2024年4月17日 17:46
阅读数 135

#define _CRT_SECURE_NO_WARNINGS  
#include <stdio.h>  
#include <stdlib.h>  
#include <stdbool.h>  
#include <math.h>  
#include <string.h>  
int main()
{
    int n;
    scanf("%d", &n);
    int arr[100] = {0};
    int count = 0;//记录表演过得小朋友人数;
    int r;        //用于接收最后结果;
    for (int i = 3; ; )
    {
        arr[i % n] = 1; //表演后退场的小朋友记为1;
        count++;
        for (int j = 0; j < 3; j++) //继续追踪未参与表演的小朋友;
        {
            i++;
            if (arr[i%n]==1) j--;

        }
        if (count == n - 1)         //当只剩一位小朋友时
        {
            r = i % n;
            break;
        }

   
    }
    if (r == 0)printf("%d", n);
    else       printf("%d", r);
    return 0;
}

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发