您的位置:首页 > 其它

hdu1896 Stones(优先队列水)

2016-03-06 21:13 274 查看
ahhh刚开始不知道怎么输入,是一个一个输跟着处理,还是全输好存起,可是一看1000000的数据量就不知道怎么搞了。。。看了别人的没想到队列居然能忍受这么大的数据,于是就开始敲,按着自己的思路,奇数的入队列,偶数的出队列,位置累加,终于1A了(好久没有一次A掉了)


#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <queue>
#include <string.h>
using namespace std;

const int N = 5000;
const int INF = 1000000;

struct node
{
int st, dis;
friend bool operator < (const node &a, const node &b)
{
if(a.st != b.st) return a.st > b.st;
else return a.dis > b.dis;
}
};

int main()
{
// freopen("in.txt", "r", stdin);
int T, n, num;
scanf("%d", &T);
while(T --)
{
priority_queue <node> q;
scanf("%d", &n);
while(n --)
{
node tmp;
scanf("%d%d", &tmp.st, &tmp.dis);
q.push(tmp);
}
num = 1;
while(q.size() > 1)
{
if(num == 1)
{
node tmp1 = q.top();
q.pop();
tmp1.st += tmp1.dis;
q.push(tmp1);
num = 0;
}
else if(num == 0)
{
q.pop();
num = 1;
}
}
node tmp2 = q.top();
printf("%d\n", tmp2.st + tmp2.dis);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  hdu