【POJ 2442】 Sequence
【题目链接】
http://poj.org/problem?id=2442
【算法】
堆
【代码】
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cerrno>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <limits>
#include <list>
#include <map>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <utility>
#include <vector>
#include <cwchar>
#include <cwctype>
#include <stack>
#include <limits.h>
using namespace std;
#define MAXM 110
#define MAXN 2010 int T,n,m,i,j;
int a[MAXM][MAXN],ans[MAXN]; struct info
{
int p,q,val;
bool last;
friend bool operator < (info a,info b)
{
return a.val > b.val;
}
} ; inline void _merge(int *a,int *b)
{
int i,j;
priority_queue< info > q;
static int res[MAXN];
info tmp;
while (!q.empty()) q.pop();
q.push((info){,,a[]+b[],false});
for (i = ; i <= n; i++)
{
tmp = q.top();
q.pop();
res[i] = tmp.val;
q.push((info){tmp.p,tmp.q+,a[tmp.p]+b[tmp.q+],true});
if (!tmp.last) q.push((info){tmp.p+,tmp.q,a[tmp.p+]+b[tmp.q],false});
}
for (i = ; i <= n; i++) a[i] = res[i];
} int main()
{ scanf("%d",&T);
while (T--)
{
scanf("%d%d",&m,&n);
for (i = ; i <= m; i++)
{
for (j = ; j <= n; j++) scanf("%d",&a[i][j]);
sort(a[i]+,a[i]+n+);
}
for (i = ; i <= n; i++) ans[i] = a[][i];
for (i = ; i <= m; i++) _merge(ans,a[i]);
for (i = ; i < n; i++) printf("%d ",ans[i]);
printf("%d\n",ans[n]);
} return ; }
【POJ 2442】 Sequence的更多相关文章
- 【poj 3090】Visible Lattice Points(数论--欧拉函数 找规律求前缀和)
题意:问从(0,0)到(x,y)(0≤x, y≤N)的线段没有与其他整数点相交的点数. 解法:只有 gcd(x,y)=1 时才满足条件,问 N 以前所有的合法点的和,就发现和上一题-- [poj 24 ...
- bzoj 2295: 【POJ Challenge】我爱你啊
2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec Memory Limit: 128 MB Description ftiasch是个十分受女生欢迎的同学,所以 ...
- 【链表】BZOJ 2288: 【POJ Challenge】生日礼物
2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 382 Solved: 111[Submit][S ...
- BZOJ2288: 【POJ Challenge】生日礼物
2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 284 Solved: 82[Submit][St ...
- BZOJ2293: 【POJ Challenge】吉他英雄
2293: [POJ Challenge]吉他英雄 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 80 Solved: 59[Submit][Stat ...
- BZOJ2287: 【POJ Challenge】消失之物
2287: [POJ Challenge]消失之物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 254 Solved: 140[Submit][S ...
- BZOJ2295: 【POJ Challenge】我爱你啊
2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 126 Solved: 90[Submit][Sta ...
- BZOJ2296: 【POJ Challenge】随机种子
2296: [POJ Challenge]随机种子 Time Limit: 1 Sec Memory Limit: 128 MBSec Special JudgeSubmit: 114 Solv ...
- BZOJ2292: 【POJ Challenge 】永远挑战
2292: [POJ Challenge ]永远挑战 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 513 Solved: 201[Submit][ ...
随机推荐
- printFinal用法示例
printFinal是一个基于jQuery的打印插件,支持打印预览,使用很简单,废话不多多说,直接上代码. <!DOCTYPE html PUBLIC "-//W3C//DTD XHT ...
- JS——void(0)
a标签中阻止跳转: <a href="javascript:;">跳转</a> <a href="javascript:void(0)&qu ...
- more
参数选项: -num 指定屏幕显示大小为num行. +num 从行号num开始显示. -s 把连续多个空行显示为一行. -p 不滚屏,而是清除整个屏幕,然后显示文本. -c 不滚屏,而是从每一屏的顶部 ...
- windows设置右键菜单
1. 打开注册表,(win + R,输入regedit) 2. 在 HKEY_CLASSES_ROOT\Directory\Background\shell 中,新建项:如(cmder),在 cmde ...
- poj3176-Cow Bowling【dp】
The cows don't use actual bowling balls when they go bowling. They each take a number (in the range ...
- Django Template(模板系统)
一.Django模板 内置模板标签和过滤器 二.常用操作 两种特殊符号: {{ }} 和 {% %} 变量相关的用: {{ }} 逻辑相关的用: {% %} 2.1 变量 在Django的模 ...
- RabbitMQ在Ubuntu上的环境搭建
1.修改/etc/apt/sources.list文件 A:命令:vi /etc/apt/sources.list B:在最后一行加上:deb http://www.rabbitmq.com/debi ...
- 35.分组聚合操作—bucket+metric
主要知识点: bucket+metric 计算分种颜色的电视的平均价格 语法: GET /tvs/sales/_search { "size" : 0, "agg ...
- 第三节:初识pandas之DataFrame(上)
DataFrame是Python中Pandas库中的一种数据结构,它类似excel,是一种二维表.
- Thesis Viva checklist
This list gives you suggestions helpful in preparing to defend your thesis: I know my thesis thoroug ...