HDUOJ 1896 Stones(简单的优先队列模拟)


原题链接
solution:简单的优先队列模拟

#include <bits/stdc++.h>
using namespace std;

int main()
{
	int t, n, res;
	cin >> t;
	while (t--)
	{
		cin >> n;
		priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int>> > q;
		for (int i = 0; i < n; ++i)
		{
			int a, b;
			cin >> a >> b;
			q.push(make_pair(a, b));
		}
		while (!q.empty()){
			q.push(make_pair(q.top().first + q.top().second, q.top().second));
			q.pop();
			res = q.top().first;
			q.pop();
		}
		cout << res << endl;
	}
	return 0;
}
全部评论

相关推荐

UtopianYou...:这个简历排版真的不太行哦,去找免费的或者花点小钱,把排版弄整齐一点吧,看着舒服。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务