【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][ ...
随机推荐
- JS——旋转木马
1.opacity和zIndex的综合运用 2.样式的数组的替换:向右边滑动---删除样式数组第一位并在数组最后添加:向左边滑动---删除样式数组最后一位并在数组前添加 3.开闭原则,只有当回调函数执 ...
- [Windows Server 2012] WordPress安全设置方法
★ 欢迎来到[护卫神·V课堂],网站地址:http://v.huweishen.com ★ 护卫神·V课堂 是护卫神旗下专业提供服务器教学视频的网站,每周更新视频. ★ 本节我们将带领大家:WordP ...
- DOS批处理命令-字符串操作
1.字符串替换 语法结构:%变量名:替换前=替换后% @set str=teh cat in teh hat @echo %str% @set str=%str:teh=the% @echo %str ...
- java主要集合类的数据结构
1).ArrayList ArrayList维护着一个对象数组.如果调用new ArrayList()后,它会默认初始一个size=10的数组. 每次add操作都要检查数组容量,如果不够,重新 ...
- Address space layout randomization
Address space layout randomization (ASLR) is a computer security technique involved in preventing ex ...
- C# Tuple 创建一个新二元集合
List<string> list1=new List<string>(); List<string> list2=new List<string>() ...
- dos命令在vba中应用
正常情况下想要遍历文件夹和子文件夹,可以采用递归的方式 Sub ListFilesTest() With Application.FileDialog(msoFileDialogFolderPicke ...
- nginx设置绑定解析实现二级域名多域名
apache(httpd)配置多个二级域名看这个链接:https://www.cnblogs.com/Crazy-Liu/p/10879928.html 网站的目录结构为/home/www├── bb ...
- CAD通过扩展记录实体向数据库读写用户自定义的全局数据(com接口VB语言)
VB代码实现如下: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 ...
- JavaFX桌面应用开发-鼠标事件和键盘事件
鼠标相关事件的操作初始代码 package application; import javafx.application.Application;import javafx.event.ActionE ...