文章

2

粉丝

0

获赞

0

访问

207

头像
约瑟夫问题的实现 题解:
P5104
发布于2026年4月7日 21:42
阅读数 122

#include<stdio.h>
#include<string.h>

struct node{
    int num;
    int flag;//用来判断是否出局
};


int main()
{
   int n,k,i,j;
   scanf("%d%d",&n,&k);
   struct node people[n+1];
   for(i=1;i<=n;i++)
   {
       people[i].num=i;
       people[i].flag=1;
   }

    int temp=1;//用来记录当前位置
    int temp2=0;//用来记录知否满k值;
    int count=n;//用来记录人数
    int ans=0;
    while(count>1)
    {
        if(people[temp].flag)
        {
            temp2++;

            if(temp2==k)
        {
            temp2=0;
            people[temp].flag=0;
           ...

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发