1 条题解

  • 1
    @ 2021-04-23 21:19:13

    稍微改改简化版的约瑟夫就出来

    #include<iostream>
    #include<list>
    using namespace std;
    int main()
    {
        list<int> a,b;
        int n,k; cin>>n>>k;
        int cnt = 1,j;
        for(int i=1; i<=n; i++)
            a.push_back(i);
        for(int i=0;i<k;i++){
            cin>>j;
            b.push_back(j);
        }
        list<int>::iterator listb=b.begin();
        list<int>::iterator it=a.begin();
        for(; a.size()>1;){
            if(cnt==*listb){
                listb++;
                if(listb==b.end())
                    listb=b.begin();
                cnt=1;
                list<int>::iterator it1=it;
                it++;
                if(it==a.end())
                    it=a.begin();
                a.erase(it1);
            }
            else{
                cnt++,it++;
                if(it==a.end())
                    it=a.begin();
            }
        }
        list<int>::iterator f=a.begin();
        cout<<*f<<" ";
        return 0;
    }
    
    
  • 1

信息

难度
7
分类
(无)
标签
递交数
284
已通过
62
通过率
22%
被复制
6
上传者