洛谷P1090 合并果子 (优先队列伪STL)
2016-07-08 16:49
435 查看
这个是用优先队列做的,自己没事干弄了一个STL(其实就是从头文件里面拷贝的),可以通过编译。
#include <iostream> #include <cstdio> #include <bits/c++config.h> #include <ext/pb_ds/tag_and_trait.hpp> #include <ext/pb_ds/detail/priority_queue_base_dispatch.hpp> #include <ext/pb_ds/detail/standard_policies.hpp> #ifndef PB_DS_PRIORITY_QUEUE_HPP #define PB_DS_PRIORITY_QUEUE_HPP namespace __gnu_pbds{ template<typename _Tv, typename Cmp_Fn = std::less<_Tv>, typename Tag = pairing_heap_tag, typename _Alloc = std::allocator<char> > class priority_queue : public detail::container_base_dispatch<_Tv, Cmp_Fn, _Alloc, Tag>::type{ public: typedef _Tv value_type; typedef Cmp_Fn cmp_fn; typedef Tag container_category; typedef _Alloc allocator_type; typedef typename allocator_type::size_type size_type; typedef typename allocator_type::difference_type difference_type; private: typedef typename detail::container_base_dispatch<_Tv, Cmp_Fn, _Alloc, Tag>::type base_type; typedef typename _Alloc::template rebind<_Tv> __rebind_v; typedef typename __rebind_v::other __rebind_va; public: typedef typename __rebind_va::reference reference; typedef typename __rebind_va::const_reference const_reference; typedef typename __rebind_va::pointer pointer; typedef typename __rebind_va::const_pointer const_pointer; typedef typename base_type::point_iterator point_iterator; typedef typename base_type::point_const_iterator point_const_iterator; typedef typename base_type::iterator iterator; typedef typename base_type::const_iterator const_iterator; priority_queue() { } priority_queue(const cmp_fn& r_cmp_fn) : base_type(r_cmp_fn) { } template<typename It> priority_queue(It first_it, It last_it) { base_type::copy_from_range(first_it, last_it); } template<typename It> priority_queue(It first_it, It last_it, const cmp_fn& r_cmp_fn) : base_type(r_cmp_fn) { base_type::copy_from_range(first_it, last_it); } priority_queue(const priority_queue& other) : base_type((const base_type& )other) { } virtual ~priority_queue() { } priority_queue& operator=(const priority_queue& other){ if(this != &other){ priority_queue tmp(other); swap(tmp); } return *this; } void swap(priority_queue& other) { base_type::swap(other); } }; } #endif using namespace std; priority_queue<int,vector<int>,greater<int> > PriQueue; int Input,sum,tot,num; void Push_In(); int main(){ Push_In(); while(PriQueue.empty()==0){ tot+=PriQueue.top(); PriQueue.pop();num++; if(num%2==0){ sum+=tot; PriQueue.push(tot); tot=0; } } cout<<sum; return 0; } void Push_In(){ int Nums; cin>>Input; for(int i=1;i<=Input;i++){ cin>>Nums; PriQueue.push(Nums); } }
相关文章推荐
- P1478
- P1035
- P1008 难度2.7
- 【题解】洛谷1164小A点菜
- 好吧,没事抒抒情
- 洛谷P1014 Cantor表
- 洛谷P2089 烤鸡
- 洛谷P1598 垂直柱状图
- 洛谷P1028 数的计算
- 洛谷P1914 小书童——密码
- 洛谷P1200 [USACO1.1]你的飞碟在这儿Your Ride Is Here
- 洛谷P1553 数字反转(升级版)
- 洛谷P1035 级数求和
- 10.1做题——洛谷P1433 吃奶酪
- 10.9做题——洛谷P1927防护伞
- 10.10做题——USACO1.2/洛谷1207双重回文数(Dual Palindromes)
- 洛谷P1196银河英雄传说
- 洛谷P1115最大子段和
- 洛谷1086/NOI题库1.13.38/NOIP2004普及组第2题 花生采摘
- 洛谷P1024/NOI题库7891(2.3)/NOIP2001提高组T1 一元三次方程求解