2037:【例5.4】约瑟夫问题 时间限制: 1000 ms 内存限制: 65536 KB 提交数: 17585 通过数: 9174 通过

#include<bits/stdc++.h>
using namespace std;
int main(){
    int a[10000]={0},n,m,x=1,y;
    cin>>n>>m;
    y=n;
    for(int i=1;i<=n;i++){    
        if(a[i]!=1){
                if(x==m){
                    cout<<i<<" ";
                    a[i]=1;
                    x=0;
                    y--;
                }
                    x++;
            }
                if(i==n)
                    i=0;
                if(y==0)
                break;
    }
    return 0;
}

 

posted @ 2022-05-25 20:55  男孩吖好朋友  阅读(954)  评论(0)    收藏  举报