2020-08-07

#include 

using namespace std;

struct cmp1
{
	bool operator ()(int& a, int& b)
	{
		return a > b;
	}
};

int main()
{
	int K = 0;
	cin >> K;
	priority_queue<int, vector<int>, cmp1> minHeap;
	vector<int> vi = { 7,4,1,0,8,5,2,9,6,3 };
	for (int i = 0; i < 10; i++)
	{
		int tmp = vi[i];
		if (i < K)
		{
			minHeap.push(tmp);
		}
		else
		{
			if (tmp <= minHeap.top())
			{
				continue;
			}
			else
			{
				minHeap.pop();
				minHeap.push(tmp);
			}
		}
	}
	while (!minHeap.empty())
	{
		cout << minHeap.top() << " ";
		minHeap.pop();
	}
}

你可能感兴趣的:(算法)