#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<stack>
#include<queue>
#include<cctype>
#include<sstream>
using namespace std;
#define pii pair<int,int>
#define LL long long int
const double eps=1e-;
const int INF=;
const int maxn=+;
int n,a[maxn][maxn];
struct node
{
int s,b;
node(int s,int b): s(s),b(b){}
bool operator < (const node &x) const
{
return s>x.s;
}
};
priority_queue<node>pq;
void he(int *A,int *B,int *C)
{
while(!pq.empty()) pq.pop();
for(int i=; i<n; i++)
{
pq.push(node(A[i]+B[],));
}
for(int i=; i<n; i++)
{
node t=pq.top();
pq.pop();
C[i]=t.s;
pq.push(node(t.s-B[t.b]+B[t.b+],t.b+));
}
}
int main()
{
//freopen("in1.txt","r",stdin);
//freopen("out.txt","w",stdout);
while(scanf("%d",&n)==)
{
for(int i=; i<n; i++)
{
for(int j=; j<n; j++)
{
scanf("%d",&a[i][j]);
}
sort(a[i],a[i]+n);
}
for(int i=; i<n; i++)
{
he(a[],a[i],a[]);
}
for(int i=; i<n-; i++) printf("%d ",a[][i]);
printf("%d\n",a[][n-]);
}
return ;
}

uva11997

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<stack>
#include<queue>
#include<cctype>
#include<sstream>
using namespace std;
#define pii pair<int,int>
#define LL long long int
const double eps=1e-;
const int INF=;
const int maxn=+;
int k,a,b,ans[+];
string s;
struct node
{
int num,t,p;
node (int num,int t,int p):num(num),t(t),p(p){}
bool operator <(const node &x)const
{
if(t!=x.t)
{
return t>x.t;
}
else
{
return num>x.num;
}
}
};
priority_queue<node>pq;
int main()
{
//freopen("in1.txt","r",stdin);
//freopen("out.txt","w",stdout);
while(cin>>s)
{
if(s[]=='#')
{
scanf("%d",&k);
for(int i=;i<k;i++)
{
node tmp=pq.top();
pq.pop();
ans[i]=tmp.num;
pq.push(node(tmp.num,tmp.t+tmp.p,tmp.p));
}
}
else
{
scanf("%d%d",&a,&b);
pq.push(node(a,b,b));
}
for(int i=;i<k;i++)
{
printf("%d\n",ans[i]);
}
}
return ;
}

uvalive 3135

uva11997 K Smallest Sums&&UVALive 3135 Argus(优先队列,多路归并)的更多相关文章

  1. 【暑假】[实用数据结构]UVa11997 K Smallest Sums

    UVa11997 K Smallest Sums  题目: K Smallest Sums You're given k arrays, each array has k integers. Ther ...

  2. UVA-11997 K Smallest Sums

    UVA - 11997 K Smallest Sums Time Limit: 1000MS   Memory Limit: Unknown   64bit IO Format: %lld & ...

  3. UVA11997 K Smallest Sums

    思路 经典的k路归并问题 问题先转换为2路的有序表归并 先让A[1~k]都和B[1]相加,然后加入堆中,取出堆顶(A[x]+B[y])之后,再放入A[x]+B[y+1] 代码 #include < ...

  4. 题解——UVA11997 K Smallest Sums

    题面 背景 输入 输出 翻译(渣自翻) 给定K个包含K个数字的表,要求将其能产生的\( k^{k} \)个值中最小的K个输出出来 题解 k路归并问题的经典问题 可以转化为二路归并问题求解 考虑A[], ...

  5. 11997 - K Smallest Sums(优先队列)

    11997 - K Smallest Sums You’re given k arrays, each array has k integers. There are kk ways to pick ...

  6. UVa 11997 K Smallest Sums 优先队列&amp;&amp;打有序表&amp;&amp;归并

    UVA - 11997 id=18702" target="_blank" style="color:blue; text-decoration:none&qu ...

  7. 【暑假】[实用数据结构]UVAlive 3135 Argus

    UVAlive 3135 Argus Argus Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %l ...

  8. D - K Smallest Sums(多路归并+贪心)

    Problem K K Smallest Sums You're given k arrays, each array has k integers. There are kk ways to pic ...

  9. 373. Find K Pairs with Smallest Sums (java,优先队列)

    题目: You are given two integer arrays nums1 and nums2 sorted in ascending order and an integer k. Def ...

随机推荐

  1. python——异常

    一.什么是异常 1.错误 从软件方面来说,错误是语法或是逻辑上的.错误是语法或是逻辑上的. 语法错误指示软件的结构上有错误,导致不能被解释器解释或编译器无法编译.这些些错误必须在程序执行前纠正. 当程 ...

  2. Linux:Ubuntu16.04下创建Wifi热点

    Linux:Ubuntu16.04下创建Wifi热点说明 1.Ubuntu16.04里面可以直接创建热点,而不用像以前的版本,还要其他辅助工具. 2.本篇文章参考自编程人生 具体步骤如下: 1. 点击 ...

  3. list列表、tuple元组、range常用方法总结

    list 列表(数组),是可迭代对象,列表是可变的所以列表的方法都是在列表本身更改的.里面看可以放各种数据类型的数据,可存储大量数据 连接列表可以使用 + 或 extend() a = [1, 3, ...

  4. yii2弹出层

    bootstrap http://getbootstrap.com/javascript/#modals https://github.com/lichunqiang/yii2-sweet-submi ...

  5. SpringBoot2.1.0 application.properties配置

    # =================================================================== # COMMON SPRING BOOT PROPERTIE ...

  6. 给二维码(图片)添加文字(水印),让生成的二维码中间带logo

    <?php //生成二维码 require_once IA_ROOT . '/framework/library/qrcode/phpqrcode.php'; QRcode::png($url, ...

  7. gst-rtsp-server编译测试

    最近在做dm368的开发,打算在368上移植个gst-rtsp-server.先在电脑上折腾了一天,终于是可以运行了. 我的虚拟机上早先已经安装了gstreamer-0.10(gstreamer版本太 ...

  8. nodejs爬虫selenium

    6.元素操作 查找元素 使用操作如何找到页面元素Webdriver的findElement方法可以用来找到页面的某个元素,最常用的方法是用id和name查找.下面介绍几种比较常用的方法. By ID假 ...

  9. R的t-test检验

    1.t-test的功能:单因素二水平的假设检验. H0:与我们想过要的结果相反的假设,比如我们想要的是两组数据的差异性,那么这个假设是:两组数据没有差异性. H1或Ha:备择假设,与H0假设相反. 2 ...

  10. 安装Discuz开源论坛

    11.添加mysql普通用户 接着上篇的lamp这篇安装Discuz 配置虚拟主机 1.打开虚拟主机配置 [root@NFS-31 ~]# vim /usr/local/apache2/conf/ht ...