HDU 1896 Stones

1089 단어 HDU
링크: http://acm.hdu.edu.cn/showproblem.php?pid=1896
우선 대기 열 을 배 웠 습 니 다:
#include <iostream>
#include <queue>
#define MAX(a,b) ((a) > (b) ? (a) : (b)) 
using namespace std;


struct node
{
	int pi;
	int di;
	friend bool operator<(node n1,node n2)
	{
		if(n1.pi!=n2.pi)	
			return n2.pi<n1.pi;
		return n2.di<n1.di;
	}
};



int main()
{
	int T;
	node tem,next;
	int num;
	int i;
	int n;
	int ans;


	scanf("%d",&T);
	while(T--)
	{
		priority_queue<node>q;
		scanf("%d",&n);
		for(i=0;i<n;i++)
		{
			scanf("%d%d",&tem.pi,&tem.di);
			q.push(tem);
		}


		num=0;
		ans=0;
		while(!q.empty())
		{
			num++;
			tem=q.top();
			q.pop();

			ans=MAX(ans,tem.pi);
			if(!(num%2))	
				continue;


			next.pi=tem.pi+tem.di;
			next.di=tem.di;
			q.push(next);
		}


		printf("%d
",ans); } return 0; }

좋은 웹페이지 즐겨찾기