1 条题解

  • 1

    冷静分析,用一个变量i代表报号,当i%2余1时出列,否则站后面

    code

    #include<bits/stdc++.h>
    using namespace std;
    queue<int> q;
    int n;
    int main(){
    	cin>>n;
    	for(int i=1;i<=n;i++) q.push(i);
    	int i=1,t;
    	while(!q.empty()){
    		if(i%2==1){
    			cout<<q.front()<<" ";
    			q.pop();
    		}
    		else{
    			q.push(q.front());
    			q.pop();
    		}
    		i++;
    	}
    	return 0;
    }
    
    • 1

    信息

    ID
    256
    时间
    1000ms
    内存
    256MiB
    难度
    3
    标签
    递交数
    21
    已通过
    19
    上传者