这题很智慧。

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. linux prefix

    指定安装路径不指定prefix,则可执行文件默认放在/usr /local/bin,库文件默认放在/usr/local/lib,配置文件默认放在/usr/local/etc.其它的资源文件放在/usr ...

  2. 【微服务系列】Spring SpringMVC SpringBoot SpringCloud概念、关系及区别

    一.正面解读 Spring主要是基于IOC反转Beans管理Bean类,主要依存于SSH框架(Struts+Spring+Hibernate)这个MVC框架,所以定位很明确,Struts主要负责表示层 ...

  3. 使用Maven命令安装jar包到仓库中

    项目中可能会碰到很多jar包,使用maven update不能更新,或者jar包是拷贝过来,不能编译的情况.此时就需要手动使用命令行安装. 例如Demo项目中提示缺少四个jar包,但是在repo中已经 ...

  4. linux mint 安装 SecureCRT

    最喜欢的ssh工具莫过于SecureCRT了,功能强大,方便易用.最近安装了mint17.1(基于ubuntu),就想安装一个SecureCRT来使用. [此SecureCRT仅作测试使用,不做商业用 ...

  5. Laravel 5.1 中如何使用模型观察者

    有时候我们需要在一个表更改后,触发某个事件,最常见的比如,首页推荐商品 1 更改了,需要清空所有首页商品缓存. 首先我们需要在建立一个观察者类,比如 App\Model\Observers\Proje ...

  6. cocos2d-x-lua如何导出自定义类到lua脚本环境

      这篇教程是基于你的工程是cocos2d-x-lua的项目,我假设你已经完全驾驭cocos-x/samples/Lua/HelloLua工程,基本明白lua和c++互调的一些原理. 我们的目的是要在 ...

  7. Unity3D笔记 切水果三 切水果

    一.创建一个Apple00,拖拽Prfabs下的Sprite命名为Apple00,添加碰撞器Box Collider,编写代码Knife Rey1.js 二.做被切的苹果 步骤和一是一样的,但是被切的 ...

  8. yii---where or该如何使用

    今天调试YII项目的时候,遇到一个奇葩的事儿,在调试 where or 查询的时候:调试语句是这样: $str = static::find()->where(['or','username' ...

  9. 蓝桥杯 - 数字排列(今有7对数字) - [两种不同的DFS思路]

    今有7对数字:两个1,两个2,两个3,...两个7,把它们排成一行.要求,两个1间有1个其它数字,两个2间有2个其它数字,以此类推,两个7之间有7个其它数字.如下就是一个符合要求的排列: 171264 ...

  10. Ubuntu:14.04.2 安装多个Linux内核

    http://blog.csdn.net/ddk3001/article/details/47340119 安装Ubuntu 14.04.2 后,内核是 3.16.0-30-generic   1.虚 ...