HDU 1896 Stones ——STL 优先队列
2014-04-12 15:39
435 查看
题目链接点击打开链接
这道题,就是用优先队列把按照题目要求把整个过程模拟处理就好了 需要注意的一点就是优先队列默认从大到小排列 要自定义排列顺序 用到运算符的重载了
这道题,就是用优先队列把按照题目要求把整个过程模拟处理就好了 需要注意的一点就是优先队列默认从大到小排列 要自定义排列顺序 用到运算符的重载了
#include<iostream> #include<cstdio> #include<string> #include<cstring> #include<cmath> #include<algorithm> #include<iomanip> #include<stdlib.h> #include<set> #include<map> #include<queue> using namespace std; struct node { friend bool operator< (node n1, node n2)//自定义排序 { if(n1.p==n2.p) return n1.d>n2.d; else return n1.p>n2.p; } int p; int d; }; int main() { int t; cin>>t; while(t--) { priority_queue<node> q; int n,i; cin>>n; for(i=0; i<n; i++) { node tn; cin>>tn.p>>tn.d; q.push(tn); } int cnt=1,distence=0; while(!q.empty()) { distence=q.top().p; if(cnt%2==0) { q.pop(); } else { node temp=q.top(); temp.p+=temp.d; q.pop(); q.push(temp); } cnt++; distence=q.top().p; } cout<<distence<<endl; } return 0; }
相关文章推荐
- HDU 1896 Stones --优先队列+搜索
- HDU 1896 Stones 【优先队列】
- HDU 1896 Stones --优先队列+搜索
- 【HDU]-1896-Stones(优先队列,好)
- hdu 1896 Stones(优先队列 Dijkstr)
- HDU 1896 Stones (优先队列的应用)
- HDU - 1896 : Stones(优先队列、有序对)
- hdu 杭电1896 Stones【优先队列】
- HDU - 1896 Stones —— 优先队列——贪心
- hdoj 1896 Stones【优先队列】
- 【搜索入门专题1】 hdu1242 J - Rescue c++ stl容器之优先队列+BFS
- HDU 1058 Humble Numbers(丑数,优先队列,STL)
- hdu 1896 优先队列的应用
- hdu 1896 优先队列的应用
- hdoj 1896 Stones 【优先队列】
- HDU1896_Stones_stl的优先队列
- hdu 1896(2013.9.15周赛D题)优先队列
- hdu 4393 Throw nails(STL之优先队列)
- hdu 1896 stones 队列
- hdu 1896 优先队列