使用STL list,本地通过洛谷RE,望有dalao指点
查看原帖
使用STL list,本地通过洛谷RE,望有dalao指点
522552
qianzhu233楼主2023/10/12 14:16

rt

#include<bits/stdc++.h>
using namespace std;
int n,m,now;
list<int> L;
int main()
{
    cin>>n>>m;
    for(int i=1;i<=n;++i)
    {
        L.push_back(i);
    }
    list<int>::iterator it=L.begin();
    while(true)
    {
    	now++;
        if(now==m)
        {
        	cout<<*it<<" ";
            L.erase(it);
            now=0;
        }
        if(L.empty())
        {
        	break;
        }
        it++;
        if(it==L.end())
        {
            it=L.begin();
        }
    }
    return 0;
}
2023/10/12 14:16
加载中...