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 ...
随机推荐
- CuteEditor.Editor+a+a+c+a+a.a() System.RuntimeType.get_Assembly() 问题解决方法
问题: Server Error in '/' Application. Attempt by method 'CuteEditor.Editor+a+a+c+a+a.a()' to access m ...
- C#中时间的Ticks属性
C#中时间的Ticks属性是一个很大的长整数,单位是 100 毫微秒.表示自 0001 年 1 月 1 日午夜 12:00:00 以来已经过的时间的以 100 毫微秒为间隔的间隔数,已经说得很清楚了, ...
- $ListView的优化机制和滑动时数据错乱的讨论
Refer:http://www.myexception.cn/mobile/1612364.html (一)Android ListView的基本用法 1.创建一个实体类Person,为其添加Get ...
- $《第一行代码:Android》读书笔记——第9章 服务
(一)Service简介 服务适合执行那种不需要和用户交互而且还要长期运行的任务.所有的服务代码都是默认运行在主线程中,需要在服务内部手动添加子线程,在子线程中执行耗时任务. (二)线程 1.线程 ...
- Git版本控制系统VCS
Git版本控制系统VCS 一.版本控制系统基本情况说明 版本控制是一种记录一个或者若干个文件内容的变化,以便将来查阅特定版本修订情况的系统 1.作用 记录文件的所有历史变化 随时可回复到任何一个历史状 ...
- java word导入导出工具类
package com.shareworx.yjwy.utils; import java.io.InputStream; import java.util.HashMap; import java. ...
- 前端之CSS样式
一.CSS 1.什么是CSS 层叠样式表(英文全称:Cascading Style Sheets)是一种用来表现HTML(标准通用标记语言的一个应用)或XML(标准通用标记语言的一个子集)等文件样式的 ...
- MongoDB的Find详解(一)
1.指定返回的键 db.[documentName].find ({条件},{键指定}) 数据准备persons.json var persons = [{name:"jim",a ...
- 【bzoj1260】涂色paint[CQOI2007](区间dp)
题目传送门:https://www.lydsy.com/JudgeOnline/problem.php?id=1260 这道题其实和codeforces607B有点像,然而做过原题的我居然没看出来.. ...
- processing学习整理---Structure
1.语法介绍:与java很相近,可以认为就是java. 2.运行命令(linux): processing-java --output=/tmp/processing-xx --run --force ...