样例不过求调

#include <algorithm>
#include <cstdio>
#include <queue>
#include <vector>

int main(void)
{
	int a, n;
	
	while (scanf("%d %d", &a, &n) == 2)
	{
		int x = a, sum = 1;
		std::priority_queue <int, std::vector <int>, std::greater <int>> b1;
		std::priority_queue <int, std::vector <int>, std::greater <int>> b2;
		
		while (sum < n)
		{
			b1.push(2 * x + 1);
			b2.push(3 * x + 1);
			
			if (b1.top() < b2.top())
			{
				x = b1.top();
				b1.pop();
			}
			else
			{
				x = b2.top();
				b2.pop();
			}
			
			sum++;
		}
		
		printf("%d ", x);
	}
	
	return 0;
}

3 个赞

考虑两个队头相等的情况,是否只pop一个队列?
另外请规范问问题格式,注明题目的标题,题面,代码带上注释

5 个赞