HDU 1896 Stones(优先队列)

来源:互联网 发布:suse linux 12 iso 编辑:程序博客网 时间:2024/05/18 03:21

简单模拟即可。

#include <queue>#include <cstdio>using namespace std;struct node{    int pos,dis;    bool operator <(const node t)const    {        if(pos!=t.pos) return pos>t.pos;        return dis>t.dis;    }};int main(){    priority_queue<node>q;    int T,n;    node t;    scanf("%d",&T);    while(T--)    {        scanf("%d",&n);        while(n--)        {            scanf("%d%d",&t.pos,&t.dis);            q.push(t);        }        bool flag=true;        while(!q.empty())        {            t=q.top();            q.pop();            if(flag)            {                flag=false;                t.pos+=t.dis;                q.push(t);            }            else flag=true;        }        printf("%d\n",t.pos);    }    return 0;}