http://poj.org/problem?id=2442

用STL写的时间为:5657MS

 #include<cstdio>
#include<algorithm>
#include<queue>
#define MAXN 2005
using namespace std;
int main()
{
int t,n,m,c;
scanf("%d",&t);
while(t--){
scanf("%d%d",&n,&m);
int a[MAXN];
priority_queue< int,vector<int>,greater<int> >q;
priority_queue< int,vector<int>,less<int> >p;
for(int i=; i<m; i++)
{
scanf("%d",&c);
q.push(c);
}
for(int j=; j<n; j++)
{
for(int k=; k<m; k++)
{
scanf("%d",&a[k]);
}
while(!q.empty())
{
int mm=q.top();
q.pop();
for(int h=; h<m; h++)
{
if(p.size()==m&&p.top()>mm+a[h])
{
p.pop();
p.push(mm+a[h]);
}
else if(p.size()<m)
{
p.push(mm+a[h]);
}
}
}
while(!p.empty())
{
q.push(p.top());
p.pop();
}
}
int mark=;
for(int i=;i<m;i++)
{
if(mark)
{
printf("%d",q.top());
mark=;
}
else printf(" %d",q.top());
q.pop();
}
printf("\n");
}
return ;
}

我用堆写的时间:3969MS

 #include<cstdio>
#include<algorithm>
#include<queue>
#define MAXN 2005
long long a[],b[];
using namespace std;
int len=,len1=;
void up1(int n)
{
a[++len]=n;
int p=len;
int q=p/;
long long m=a[p];
while(q>=&&m<a[q])
{
a[p]=a[q];
p=q;
q=p/;
}
a[p]=m;
}
void up2(int n)
{
b[++len1]=n;
int p=len1;
int q=p/;
long long m=b[p];
while(q>=&&m>b[q])
{
b[p]=b[q];
p=q;
q=p/;
}
b[p]=m;
}
void down1(int p)
{
a[]=a[len--];
int q=p*;
long long m=a[p];
while(q<=len)
{
if(q<len&&a[q]>a[q+])
q++;
if(a[q]>=m) break;
else
{
a[p]=a[q];
p=q;
q=p*;
}
}
a[p]=m;
}
int pop1()
{
long long r=a[];
return r;
}
int pop2()
{
long long r=b[];
return r;
}
void down2(int p)
{
b[]=b[len1--];
int q=p*;
long long m=b[p];
while(q<=len1)
{
if(q<len1&&b[q]<b[q+])
q++;
if(b[q]<=m) break;
else
{
b[p]=b[q];
p=q;
q=p*;
}
}
b[p]=m;
} int main()
{
int t,n,m,c;
scanf("%d",&t);
while(t--){
scanf("%d%d",&n,&m);
int aa[MAXN];
for(int i=; i<m; i++)
{
scanf("%d",&c);
up1(c);
}
for(int j=; j<n; j++)
{
for(int k=; k<m; k++)
{
scanf("%d",&aa[k]);
}
while(len!=)
{
int mm=pop1();
down1();
for(int h=; h<m; h++)
{
if(len1>=m&&b[]>mm+aa[h])
{
down2();
up2(mm+aa[h]);
}
else if(len1<m)
{
up2(mm+aa[h]);
}
}
}
while(len1!=)
{
up1(b[]);
down2();
}
}
int mark=;
for(int i=;i<m;i++)
{
if(mark)
{
printf("%lld",a[]);
mark=;
}
else printf(" %lld",a[]);
down1();
}
printf("\n");
}
return ;
}

Sequence的更多相关文章

  1. oracle SEQUENCE 创建, 修改,删除

    oracle创建序列化: CREATE SEQUENCE seq_itv_collection            INCREMENT BY 1  -- 每次加几个              STA ...

  2. Oracle数据库自动备份SQL文本:Procedure存储过程,View视图,Function函数,Trigger触发器,Sequence序列号等

    功能:备份存储过程,视图,函数触发器,Sequence序列号等准备工作:--1.创建文件夹 :'E:/OracleBackUp/ProcBack';--文本存放的路径--2.执行:create or ...

  3. DG gap sequence修复一例

    环境:Oracle 11.2.0.4 DG 故障现象: 客户在备库告警日志中发现GAP sequence提示信息: Mon Nov 21 09:53:29 2016 Media Recovery Wa ...

  4. Permutation Sequence

    The set [1,2,3,-,n] contains a total of n! unique permutations. By listing and labeling all of the p ...

  5. [LeetCode] Sequence Reconstruction 序列重建

    Check whether the original sequence org can be uniquely reconstructed from the sequences in seqs. Th ...

  6. [LeetCode] Binary Tree Longest Consecutive Sequence 二叉树最长连续序列

    Given a binary tree, find the length of the longest consecutive sequence path. The path refers to an ...

  7. [LeetCode] Verify Preorder Sequence in Binary Search Tree 验证二叉搜索树的先序序列

    Given an array of numbers, verify whether it is the correct preorder traversal sequence of a binary ...

  8. [LeetCode] Longest Consecutive Sequence 求最长连续序列

    Given an unsorted array of integers, find the length of the longest consecutive elements sequence. F ...

  9. [LeetCode] Permutation Sequence 序列排序

    The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all of the p ...

  10. Leetcode 60. Permutation Sequence

    The set [1,2,3,-,n] contains a total of n! unique permutations. By listing and labeling all of the p ...

随机推荐

  1. SVN安装图解

    SVN服务器搭建和使用(一) Subversion是优秀的版本控制工具,其具体的的优点和详细介绍,这里就不再多说. 首先来下载和搭建SVN服务器. 现在Subversion已经迁移到apache网站上 ...

  2. Hadoop在linux下无法启动DataNode解决方法

    最近重新捡起了Hadoop,所以博客重新开张- 首先描述一下我的问题:这次我使用eclipse在Ubuntu上运行hadoop程序.首先,按照厦门大学数据库实验室的eclipse下运行hadoop程序 ...

  3. Rocketmq整体分析

    之前本人在实际的生产环境中,使用过activemq和rabbitmq消息队列,在使用过程中出现一些难以解决的问题,本文通过产品选型.网络架构和核心特性分析了rocketmq的优势和特性. 产品选型 我 ...

  4. UVa 108: Maximum Sum

    这道题用暴力解法+动态规划.分析如下: 对于某个1*m的矩阵,即一个数列,求其maximal sub-rectangle,可以通过求最大长连续字串和来求得(这个用到了动态规划). 那么对于n*m的矩阵 ...

  5. 监控 Linux 性能的 18 个命令行工具

    http://www.oschina.net/translate/command-line-tools-to-monitor-linux-performance 1.Top-Linux进程监控 Lin ...

  6. JQ滑动导航菜单的实现

    前言:不多说直接看效果!!! 这样的菜单我们在一般的网站上见到的也比较多,有比较好的用户体验!   原理:这个很重要,任何的特效只要原理搞明白了,实现起来都是很容易的!这个特效的原理很简单,菜单的样式 ...

  7. Linux后台开发面试问题汇总

    个人从事安全后台开发,当然是linux环境下的了.举几个常见的问题.1. 数据结构基础.比如实现一个最简单的哈希表.2. 操作系统基础.linux进程模型,堆/栈的区别,大概的位置,各往哪个方向生长, ...

  8. ie兼容CSS3渐变写法

    在css3之前要想做背景色渐变就只能采用添加背景图片的方法,但是随着css3:linear-gradient属性的出现,就可以避免使用添加背景图片的方法,从而优化了性能.但是inear-gradien ...

  9. poj 1125 Stockbroker Grapevine (dij优化 0ms)

    #include<iostream> #include<cstdio> #include<cstring> #include<queue> #defin ...

  10. js动态添加table 数据tr td

    成果库修改:      要求主题列表随成果类型改变而改变      网上查询资料后开工,在成果类型下拉框添加change()事件触发Dwr,查询主题集合——动态创建/编辑Table      概要代码 ...