uva11997 K Smallest Sums&&UVALive 3135 Argus(优先队列,多路归并)
#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(优先队列,多路归并)的更多相关文章
- 【暑假】[实用数据结构]UVa11997 K Smallest Sums
UVa11997 K Smallest Sums 题目: K Smallest Sums You're given k arrays, each array has k integers. Ther ...
- UVA-11997 K Smallest Sums
UVA - 11997 K Smallest Sums Time Limit: 1000MS Memory Limit: Unknown 64bit IO Format: %lld & ...
- UVA11997 K Smallest Sums
思路 经典的k路归并问题 问题先转换为2路的有序表归并 先让A[1~k]都和B[1]相加,然后加入堆中,取出堆顶(A[x]+B[y])之后,再放入A[x]+B[y+1] 代码 #include < ...
- 题解——UVA11997 K Smallest Sums
题面 背景 输入 输出 翻译(渣自翻) 给定K个包含K个数字的表,要求将其能产生的\( k^{k} \)个值中最小的K个输出出来 题解 k路归并问题的经典问题 可以转化为二路归并问题求解 考虑A[], ...
- 11997 - K Smallest Sums(优先队列)
11997 - K Smallest Sums You’re given k arrays, each array has k integers. There are kk ways to pick ...
- UVa 11997 K Smallest Sums 优先队列&&打有序表&&归并
UVA - 11997 id=18702" target="_blank" style="color:blue; text-decoration:none&qu ...
- 【暑假】[实用数据结构]UVAlive 3135 Argus
UVAlive 3135 Argus Argus Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %l ...
- 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 ...
- 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 ...
随机推荐
- 【HTTP】WEB机器人
<HTTP权威指南>学习摘要 Web Robot的自活跃(self-animating)用户代理. Web机器人是在不需要人工干预的情况下,自动进行一系列Web事务处理的软件程序,别名“爬 ...
- Java FAQ -- "Exception in thread 'main' java.lang.UnsupportedClassVersionError:"
OS:Ubuntu 最近重新学习Java,写了一段很小的程序,如下: public class Hello{ public static void main(String args[]){ Syste ...
- 【转】JAVA学习笔记----PL/SQL最差实践
1. 超长的PL/SQL代码 影响:可维护性,性能 症状: 在复杂的企业应用中,存在动辄成百上千行的存储过程或上万行的包.为什么是最差: 太长的PL/SQL代码不利于阅读,第三方工 ...
- 使用ajax进行汽车详情表的查询
主界面代码 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w ...
- JavaScript:学习笔记(2)——基本概念与数据类型
JavaScript:学习笔记(2)——基本概念与数据类型 语法 1.区分大小写.Test 和 test 是完全不同的两个变量. 2.语句最好以分号结束,也就是说不以分号结束也可以. 变量 1.JS的 ...
- Apache commons-io实现多文件读取和写入
需求: "E:/data/"目录下有四个文件夹,如下: 每个文件夹下有几个.csv文件,如下: 将每个文件夹下的.csv文件合并成一个以该文件夹命名的.csv文件. 做法: 找到& ...
- 配置树莓派3和局域网NTP服务器实现内网时间校准
一.配置局域网NTP服务器 1.安装ntp-4.2.8p5-win32-setup.exe 下载地址:https://www.meinbergglobal.com/english/sw/ntp.htm ...
- 生信概念之global alignment VS local alignment
- 用requests登录微信网页版,并接收发送消息
首先,网页版微信登录大致分为以下几个流程(都是大家可以通过抓包得到): 1.登陆主页后,会生成一个UUID,这是个用户标识,在后面请求二维码会用到 def get_uuid(self): '''获取u ...
- centos 源码安装php5.5
系统环境: CentOS 6.5 / 7.0 x86_64 Fedora 20 x86_64下载 PHP 源码包 # wget http://cn2.php.net/distributions/php ...