输入:n,m,k,人数,死亡数字,存活数量 输出:将存活的人以编号从小到大输出 输入:60 17 5 输出:7 9 10 45 58 #include <iostream> #include <queue> #include <algorithm> using namespace std; queue<int> q;//创建一个约瑟夫队列 int main(){ int N,M; cin>>N>>M; for(int i=1;i<=N;i++) q.push(i); int c=1; while(q.size()!=k){ if(c==M){ cout<<q.front()<<" "; q.pop(); c=1; } else{ q.push(q.front()); q.pop(); c++; } } int a[1000]={},j=0; while(!q.empty()){ a[j++]=q.front(); q.pop(); } sort(a,a+j); for(int i=0;i<j;i++) cout<<a[i]<<" "; return 0; } //单词: queue 队列 (责任编辑:admin) |