poj 2442【堆应用+STL Heap】
来源:互联网 发布:linux getfattr 编辑:程序博客网 时间:2024/06/05 18:29
本题要维护两个大根堆,用来循环维护。。。注意STL heap里的复杂度
#include <vector>#include <list>#include <map>#include <set>#include <queue>#include <string.h>#include <deque>#include <stack>#include <bitset>#include <algorithm>#include <functional>#include <numeric>#include <utility>#include <sstream>#include <iostream>#include <iomanip>#include <cstdio>#include <cmath>#include <cstdlib>#include <limits.h>using namespace std;int lowbit(int t){return t&(-t);}int countbit(int t){return (t==0)?0:(1+countbit(t&(t-1)));}int gcd(int a,int b){return (b==0)?a:gcd(b,a%b);}#define LL long long#define PI acos(-1.0)#define N 2010#define MAX INT_MAX#define MIN INT_MIN#define eps 1e-8#define FRE freopen("a.txt","r",stdin)int a[N],b[N];int main(){ int t; scanf("%d",&t); while(t--) { int n,m; scanf("%d%d",&n,&m); int i,j,k; for(i=0;i<m;i++) scanf("%d",&a[i]); make_heap(a,a+m);//复杂度O(n) int num; for(i=1;i<n;i++){ for(j=0;j<m;j++){ scanf("%d",&num); if(i&1){ if(j==0){ for(k=0;k<m;k++){ b[k]=a[k]+num; } } else{ for(k=0;k<m;k++){ if(num+a[k]<b[0]){ pop_heap(b,b+m);//复杂度O(log(n)) b[m-1]=num+a[k]; push_heap(b,b+m);//把b[m-1]推进去堆里再做成一个堆,复杂度O(log(n)) } } } } else{ if(j==0){ for(k=0;k<m;k++){ a[k]=b[k]+num; } } else{ for(k=0;k<m;k++){ if(num+b[k]<a[0]){ pop_heap(a,a+m); a[m-1]=num+b[k]; push_heap(a,a+m); } } } } } } if(!(n&1)){ sort(b,b+m); for(i=0;i<m;i++) printf("%d ",b[i]); puts(""); } else{ sort(a,a+m); for(i=0;i<m;i++) printf("%d ",a[i]); puts(""); } } return 0;}
- poj 2442【堆应用+STL Heap】
- STL之heap堆的应用
- STL heap堆
- STL 堆(heap)
- STL之heap 堆
- STL 堆 heap
- STL heap 堆
- 手写堆heap(STL的heap算法)
- STL算法(Algorithms):堆(heap)
- STL的 heap 堆实现
- STL 堆heap的用法
- 关于 STL 中的 heap ( 堆 )
- STL——heap堆
- STL系列 heap 堆-解析
- STL——堆heap
- POJ 2442 Sequence 堆的思想的应用 STL 堆学习
- STL heap简单应用
- poj 2442(堆的stl实现)
- eclipse中java操作mysql数据库注意事项
- Myeclipse--中Project的svn图标状态(同步标记)不显示问题
- MyEclipse删除一行快捷键
- Windows密码大破解
- uCOS-II移值过程实例讲解
- poj 2442【堆应用+STL Heap】
- 数据结构总结
- Android SDK Android NDK 官方下载地址
- C++ 指针典型应用
- Android控件开发之TabWidget
- UBuntu 11.04上架设ACE日志服务器
- Ubuntu无盘工作站安装详细步骤
- ASP.Net 4.0 对SEO增强一:使用MetaDescription,MetaKeywords,RedirectPermanant等
- 解决MySQL在终端和网页中显示乱码问题