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;
}
#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 5366】The mook jong 详解
- 【HDU 2136】Largest prime factor 详细图解
- HDU 1568
- HDU1290
- HDU1568(Fobonacci公式)
- HDU ACM Step 2.2.2 Joseph(约瑟夫环问题)
- HDU 1405
- HDU 1297
- hdu 1205
- hdu 2087
- hdu 1016
- HDU 4898 The Revenge of the Princess’ Knight ( 2014 Multi-University Training Contest 4 )
- HDU 5592 ZYB's Premutation 线段树(查找动态区间第K大)
- HDU 5240 Exam (好水的题)
- HDU5237 Base64 大模拟
- HDU 1000
- HDU 1001
- 2015-11-11 hdu新生赛 A题(AC)
- 2015-11-11 hdu新生赛 C题(结束后一发AC)
- 2015-11-11 hdu新生赛 E题(结束后一发AC)