Sequence《优先队列》
Description
Input
Output
Sample Input
1
2 3
1 2 3
2 2 3
Sample Output
3 3 4 这个题的意思不是很难理解,关键是思想,一点点算肯定超时了;
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<queue>
using namespace std;
int main()
{
int m,n,t,a[],b[],i,j;
priority_queue<int,vector<int>,less<int> >que;
scanf("%d",&t);
while(t--)
{
scanf("%d %d",&m,&n);
m--;
for(i=; i<n; i++)
scanf("%d",&a[i]);
sort(a,a+n);
while(m--)
{
for(i=; i<n; i++)
{
scanf("%d",&b[i]);
que.push(a[]+b[i]);//先进去N个
}
sort(b,b+n);//这个应该会用了
for(i=; i<n; i++)
{
for(j=; j<n; j++)
{
if(a[i]+b[j]>que.top())//因为有sort排序,所以,后面只会更大,可以break;
break;
que.pop();
que.push(a[i]+b[j]);
}
}
for(i=n-; i>-; i--)
{
a[i]=que.top();
que.pop();
}
}
printf("%d",a[]);
for(i=; i<n; i++)
printf(" %d",a[i]);
printf("\n");
}
return ;
}
Hint
Sequence《优先队列》的更多相关文章
- oracle SEQUENCE 创建, 修改,删除
oracle创建序列化: CREATE SEQUENCE seq_itv_collection INCREMENT BY 1 -- 每次加几个 STA ...
- Oracle数据库自动备份SQL文本:Procedure存储过程,View视图,Function函数,Trigger触发器,Sequence序列号等
功能:备份存储过程,视图,函数触发器,Sequence序列号等准备工作:--1.创建文件夹 :'E:/OracleBackUp/ProcBack';--文本存放的路径--2.执行:create or ...
- DG gap sequence修复一例
环境:Oracle 11.2.0.4 DG 故障现象: 客户在备库告警日志中发现GAP sequence提示信息: Mon Nov 21 09:53:29 2016 Media Recovery Wa ...
- Permutation Sequence
The set [1,2,3,-,n] contains a total of n! unique permutations. By listing and labeling all of the p ...
- [LeetCode] Sequence Reconstruction 序列重建
Check whether the original sequence org can be uniquely reconstructed from the sequences in seqs. Th ...
- [LeetCode] Binary Tree Longest Consecutive Sequence 二叉树最长连续序列
Given a binary tree, find the length of the longest consecutive sequence path. The path refers to an ...
- [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 ...
- [LeetCode] Longest Consecutive Sequence 求最长连续序列
Given an unsorted array of integers, find the length of the longest consecutive elements sequence. F ...
- [LeetCode] Permutation Sequence 序列排序
The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all of the p ...
- 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 ...
随机推荐
- richTextBox1 转到行号
private void button2_Click(object sender, EventArgs e) { Win32CommonDialog.frm_GOTO frm = new ...
- 利用ssh传输文件 分类: 服务器搭建 Raspberry Pi 2015-04-12 18:47 58人阅读 评论(0) 收藏
在linux下一般用scp这个命令来通过ssh传输文件. 1.从服务器上下载文件 scp username@servername:/path/filename /var/www/local_dir(本 ...
- Cubieboard 开箱和入门 | Name5566 分类: cubieboard 2014-11-08 17:27 251人阅读 评论(0) 收藏
Cubieboard 开箱和入门 2014 年 01 月 29 日 by name5566 Categories: Computer Science, Cubieboard Hello Cubiebo ...
- Nubia Z5S(高通公司MSM8974) QHSUSB_BULK砖的方法节省模式(随着win7在恢复recovery分区案例)
Nubia Z5S在某些异常情况或按组合键进入QHSUSB_BULK状态, 这种模式的现象, 猜想windows(实例win7)即使在数据线, 它会出现在计算机n载,甚至会提示要格式化某些分区(这里要 ...
- android 10 事件
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layo ...
- HTML表单介绍
表单语法结构如下: <form action="url" method="get|post" name="value" enctype ...
- Java基础知识强化之集合框架笔记24:ArrayList存储自定义对象并遍历
1. ArrayList存储自定义对象并遍历 2. 代码示例: Student.java,如下: package cn.itcast_01; public class Student { privat ...
- Linux 用户与用户组
1 Linux 用户与组 Linux是一个多用户多任务操作系统.多用户可以在同一时间内登录同一个系统执行各自不同的任务,而互不影响. 1.1 Linux下用户的角色分类 Linux用户的角色分为3 ...
- 访问nginx提示gateway timeout 504 ,发现总是当调用时间超过30s时提示504错误
解决办法: 需要修改php-fpm的配置文件 request_terminate_timeout=30s 参考文档: http://baike.baidu.com/view/641394.htm ht ...
- CouchBase 遇到问题笔记(一)
刚开始看CouchBase,按照官网给出的示例,边敲边理解,遇到了一个很奇怪的问题,如下代码: IView<IViewRow> view = client.GetView("be ...