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. 怎样在loop中处理异常

    怎样在loop中处理异常,而不跳出 出现符号“exception”在需要下下列之一时的解决办法; 如果sql中发生异常,我们可以用 exception       when others then d ...

  2. Java学习的随笔(3)接口

    首先是一段<Java编程思想>中,对接口的解释:“interface这个关键字产生一个完全抽象的类,它根本就没有提供任何具体的实现.它允许创建者确定方法名.参数列表.返回类型,但是没有任何 ...

  3. 物联网MQTT协议分析和开源Mosquitto部署验证

    在<物联网核心协议—消息推送技术演进>一文中已向读者介绍了多种消息推送技术的情况,包括HTTP单向通信.Ajax轮询.Websocket.MQTT.CoAP等,其中MQTT协议为IBM制定 ...

  4. win32 api 文件操作!

    CreateFile打开文件要对文件进行读写等操作,首先必须获得文件句柄,通过该函数可以获得文件句柄,该函数是通向文件世界的大门. ReadFile从文件中读取字节信息.在打开文件获得了文件句柄之后, ...

  5. RT: TCP REUSEADDR or REUSEPORT

    Welcome to the wonderful world of portability... or rather the lack of it. Before we start analyzing ...

  6. Bernese单点定位数据准备及处理

    原创作者 blog :http://yifeiyao.blog.163.com/blog/static/2058932752012669731170/1.准备所需用的数据文件,如下: 原始观测.O文件 ...

  7. CI 模型的使用M与C之间的调用

    CI是PHP一个比较轻,并且好用的一个框架 分层也是分的比较清晰的一个 这里先展示MODEL 放在application/models 目录下面user_model.php <?php clas ...

  8. 一个tomcat部署俩个java web项目

    2.发布的时候可以发布成war包,用项目名称右键export,选择项目名称,还有发布的路径,即tomcat下的路径,参考http://zhidao.baidu.com/link?url=imOu0Uu ...

  9. 【转】 iOS开发数据库篇—SQLite简单介绍

    开始学SQLite啦, 原文: http://www.cnblogs.com/wendingding/p/3868893.html iOS开发数据库篇—SQLite简单介绍 一.离线缓存 在项目开发中 ...

  10. iOS程序的完整启动过程(有storyboard)

    1.先执行main函数,main内部会调用UIApplicationMain函数 2.UIApplicationMain函数里面做了什么事情:1> 创建UIApplication对象 2> ...