这题很智慧。

VJ上4000多ms

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

大神的代码(VJ上才刚900ms)

#include <iostream>
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<algorithm>
#include<queue>
#include<set>
#include<string>
using namespace std;
int main()
{
priority_queue<int,vector<int>,less<int> >p;
int n,m,i,j,a[],b[],t,k;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&m);
for(i=; i<m; i++)
scanf("%d",&a[i]);
sort(a,a+m);
for(k=; k<n; k++)
{
for(i=; i<m; i++)
{
scanf("%d",&b[i]);
p.push(a[]+b[i]);
}
sort(b,b+m);
for(i=; i<m; i++)
{
for(j=; j<m; j++)
{
if(a[i]+b[j]>p.top())
break;
p.pop();
p.push(a[i]+b[j]);
}
}
for(i=; i<m; i++)
{
a[m-i-]=p.top();
p.pop();
}
}
for(i=; i<m-; i++)
printf("%d ",a[i]);
printf("%d\n",a[m-]);
}
}

Sequence(priority_queue)的更多相关文章

  1. STL之容器适配器priority_queue

    priority_queue(优先队列)是一个拥有权值观念的queue,它允许加入新元素,删除旧元素,审视元素值等功能.由于这是一个queue,所以只允许在底端加入元素,并从顶端取出元素, 除此之外别 ...

  2. 128. Longest Consecutive Sequence(leetcode)

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

  3. STL--容器适配器(queue、priority_queue、stack)

    适配器(Adaptor)是提供接口映射的模板类.适配器基于其他类来实现新的功能,成员函数可以被添加.隐藏,也可合并以得到新的功能. STL提供了三个容器适配器:queue.priority_queue ...

  4. POJ 2442 Sequence

    Pro. 1 给定k个有序表,取其中前n小的数字.组成一个新表,求该表? 算法: 由于  a1[1] < a1[2] < a1[3] ... <a1[n] a2[1] < a2 ...

  5. Sequence 分类: 栈和队列 2015-08-05 10:10 2人阅读 评论(0) 收藏

    Sequence Time Limit: 6000MS Memory Limit: 65536K Total Submissions: 8277 Accepted: 2708 Description ...

  6. Sequence《优先队列》

    Description Given m sequences, each contains n non-negative integer. Now we may select one number fr ...

  7. STL 之 queue、priority_queue 源代码剖析

    /* * Copyright (c) 1994 * Hewlett-Packard Company * * Permission to use, copy, modify, distribute an ...

  8. STL--F - Sequence(n*m-&gt;之前的最低要求m个月)

    F - Sequence Time Limit:6000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit ...

  9. POJ 2442 - Sequence - [小顶堆][优先队列]

    题目链接:http://poj.org/problem?id=2442 Time Limit: 6000MS Memory Limit: 65536K Description Given m sequ ...

随机推荐

  1. 【大数据系列】hadoop单节点安装官方文档翻译

    Hadoop: Setting up a Single Node Cluster. HADOOP:建立单节点集群 Purpose Prerequisites Supported Platforms R ...

  2. 剑指offer题目记录

    1.如下为类型CMyString的声明,请为该类型添加赋值运算符函数. class CMyString { public: CMyString(char* pData = NULL); CMyStri ...

  3. C语言中scanf函数的实现

    接上一篇C语言中可变参数函数实现原理,从理论上详细介绍了C语言中可变参数函数的实现,这一篇从minix内核源码中的scanf函数入手,学习C语言经典可变参数函数的实现过程 在scanf.c文件中,可以 ...

  4. DragonBones龙骨插槽的隐藏

    参考: 插槽中对象的显示与隐藏问题 let factory = dragonBones.EgretFactory.factory; factory.parseDragonBonesData(RES.g ...

  5. VS2013打开2008的项目

    找到 .csproj 后缀的文件.然后右键选择文本打开. 找到下面一段话: <ProjectTypeGuids>-00065b846f21};{fae04ec0-301f-11d3-bf4 ...

  6. Pexpect学习:

    pexecpt run用法:格式:run(command,timeout=-1,withexitstatus=False,events=None,extra_args=None,logfile=Non ...

  7. jdbc(1)(三)DBCP、C3P0、Proxool 、 BoneCP开源连接池的简介

     简介          使用评价  项目主页  DBCP DBCP是一个依赖Jakarta commons-pool对象池机制的数据库连接池.DBCP可以直接的在应用程序用使用 可以设置最大和最小连 ...

  8. Ubuntu 16.04系统下安装Discuz出现“HTTP ERROR 500”目前无法处理此请求

    问题:当我们在Ubuntu 16.04系统下安装Disucz X3时,修改好文件的权限,浏览器输入地址安装时出现如下图所示问题: 问题查询: 在终端输入: tail -f /var/log/apach ...

  9. vim配置函数跳转(c/c++)

    暂时草记一下,有时间好好整理 ctags 如果只是查看函数与变量是在哪里定义的,用ctags就可以了. ctrl+]跳到定义的地方,ctrl+t跳回来. 想要像IDE那样在旁边显示函数与变量列表,用t ...

  10. RabbitMQ 安装和说明

    一.安装 1. 下载源码,RabbitMQ是使用Erlang开发,所以安装RabbitMQ前需要先安装Erlang.官方推荐从源码安装Erlang,因此下面开始从源码安装OTP 17.0.下载OTP ...