UVA_11129_An antiarithmetic permutation

#include<iostream>  
#include<cstdio>  
#include<sstream>      
#include<string>      
#include<vector>      
#include<list>      
#include<set>      
#include<map>      
#include<stack>      
#include<queue>      
#include<algorithm>      
#include<cmath>      
#pragma warning(disable:4996)      
using std::cin;
using std::cout;
using std::endl;
using std::stringstream;
using std::string;
using std::vector;
using std::list;
using std::pair;
using std::set;
using std::multiset;
using std::map;
using std::multimap;
using std::stack;
using std::queue;
void recur(vector<int>value)
{
	if (value.size() == 2)
	{
		printf(" %d %d", value[0],value[1]);
		return;
	}
	if (value.size() == 1)
	{
		printf(" %d", value[0]);
		return;
	}
	vector<int>value1, value2;
	for (size_t i = 0; i < value.size(); i+=2)
	{
		value1.push_back(value[i]);
	}
	for (size_t i = 1; i < value.size(); i += 2)
	{
		value2.push_back(value[i]);
	}
	recur(value1);
	recur(value2);
}
int main()
{
	//freopen("input.txt", "r", stdin);  
	//freopen("output.txt","w",stdout);   
	int n;
	while (cin >> n)
	{
		if (!n)
		{
			break;
		}
		cout << n << ':';
		vector<int>value;
		for (int i = 0; i < n; i++)
		{
			value.push_back(i);
		}
		recur(value);
		cout << endl;
	}
	return 0;
}

你可能感兴趣的:(uva,and,divide,conquer)