HDU - 1276 (士兵队列训练问题)

点此进入链接:题目链接

思路1, 直接数组模拟

思路2,用队列

#include
#include
#include
using namespace std;
const int maxn = 100010;
const int MAXL = 100010;


int main(){
	int T;
	cin >> T;
	while(T--){
		int n;
		cin >> n;
		bool flag = 0;
		queue q;
		for(int i = 1; i <= n; i++){
			q.push(i);
		}
		while(q.size() > 3){
			int len = q.size();
			for(int i = 1; i <= len ; i++){
				int temp = q.front();
				q.pop();
				if(i % 2 != 0)
					q.push(temp);
			}
			if(q.size() <= 3) 
				break;
			len = q.size();
			for(int i = 1 ;i <= len; i++){
				int temp = q.front();
				q.pop();
				if(i % 3 != 0)
					q.push(temp);
			}
		}
		while(q.size() > 1){
			cout << q.front() << " ";
			q.pop();
		}
		cout << q.front() << endl;
	}
	return 0;
} 

 

你可能感兴趣的:(~~~~~STL容器~~~~~)