HDU 1896 Stones(优先队列)

  还是优先队列

#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;
#define maxn 100010
struct Node
{
int x,y,id;
friend bool operator < (Node a,Node b)
{
if(a.x != b.x) return a.x > b.x;
else if(a.y != b.y) return a.y > b.y;
else return a.id < b.id;
}
} node[maxn];
priority_queue<Node>que;
int main()
{
int t,n;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(int i = ; i < n; i++)
{
scanf("%d%d",&node[i].x,&node[i].y);
node[i].id = i+;
que.push(node[i]);
}
int tot = ,maxt = -;
while(!que.empty())
{
tot++;
Node tmp = que.top();
que.pop();
if(tot & == )
{
Node next = tmp;
next.x = tmp.x + tmp.y;
if(next.x > maxt) maxt = next.x;
que.push(next);
}
}
printf("%d\n",maxt);
}
return ;
}
上一篇:HDU 1896 Stones (优先队列)


下一篇:如何把函数都用promise方式实现?