Swordsman

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 2587    Accepted Submission(s): 791

Problem Description
Lawson is a magic swordsman with k kinds of magic attributes v1,v2,v3,…,vk. Now Lawson is faced with n monsters and the i-th monster also has k kinds of defensive attributes ai,1,ai,2,ai,3,…,ai,k. If v1≥ai,1 and v2≥ai,2 and v3≥ai,3 and … and vk≥ai,k, Lawson can kill the i-th monster (each monster can be killed for at most one time) and get EXP from the battle, which means vj will increase bi,j for j=1,2,3,…,k.
Now we want to know how many monsters Lawson can kill at most and how much Lawson's magic attributes can be maximized.
 
Input
There are multiple test cases. The first line of input contains an integer T, indicating the number of test cases. For each test case:
The first line has two integers n and k (1≤n≤105,1≤k≤5).
The second line has k non-negative integers (initial magic attributes) v1,v2,v3,…,vk.
For the next n lines, the i-th line contains 2k non-negative integers ai,1,ai,2,ai,3,…,ai,k,bi,1,bi,2,bi,3,…,bi,k.
It's guaranteed that all input integers are no more than 109 and vj+∑i=1nbi,j≤109 for j=1,2,3,…,k.

It is guaranteed that the sum of all n ≤5×105.
The input data is very large so fast IO (like `fread`) is recommended.

 
Output
For each test case:
The first line has one integer which means the maximum number of monsters that can be killed by Lawson.
The second line has k integers v′1,v′2,v′3,…,v′k and the i-th integer means maximum of the i-th magic attibute.
 
Sample Input
1
4 3
7 1 1
5 5 2 6 3 1
24 1 1 1 2 1
0 4 1 5 1 1
6 0 1 5 3 1
 
Sample Output
3
23 8 4
 
Hint

For the sample, initial V = [7, 1, 1]

① kill monster #4 (6, 0, 1), V + [5, 3, 1] = [12, 4, 2]
② kill monster #3 (0, 4, 1), V + [5, 1, 1] = [17, 5, 3]
③ kill monster #1 (5, 5, 2), V + [6, 3, 1] = [23, 8, 4]
After three battles, Lawson are still not able to kill monster #2 (24, 1, 1)
because 23 < 24.
 
Source

解析 策略当然是先选最小的符合条件的在一步一步扩大,所以我们就借助优先队列来解决,把上一个满足属性条件的怪兽 转移到下一个优先队列 然后当它被标记为了k次那么就可以杀掉他了,加到属性上 进行下一步操作。

必须用这个读入挂不然会超时,注意debug时不能使用读入挂,提交的时候改过来就可以。

AC代码

 #include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(a) (a).begin(), (a).end()
#define fillchar(a, x) memset(a, x, sizeof(a))
#define huan printf("\n")
#define debug(a,b) cout<<a<<" "<<b<<" "<<endl
#define ffread(a) fastIO::read(a)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn=5e5+,inf=0x3f3f3f3f;
const ll mod=1e9+;
#define reads(n) FastIO::read(n)
namespace FastIO
{
const int SIZE = << ;
char buf[SIZE], obuf[SIZE], str[];
int bi = SIZE, bn = SIZE, opt;
int read(char *s)
{
while (bn)
{
for (; bi < bn && buf[bi] <= ' '; bi++);
if (bi < bn)
break;
bn = fread(buf, , SIZE, stdin);
bi = ;
}
int sn = ;
while (bn)
{
for (; bi < bn && buf[bi] > ' '; bi++)
s[sn++] = buf[bi];
if (bi < bn)
break;
bn = fread(buf, , SIZE, stdin);
bi = ;
}
s[sn] = ;
return sn;
}
bool read(int& x)
{
int n = read(str), bf;
if (!n)
return ;
int i = ;
if (str[i] == '-')
bf = -, i++;
else
bf = ;
for (x = ; i < n; i++)
x = x * + str[i] - '';
if (bf < )
x = -x;
return ;
}
};
priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > >q[];
int a[maxn][],v[],vis[maxn];
int main()
{
int t,n,k;
reads(t);
//cin>>t;
while(t--)
{
//cin>>n>>k;
reads(n);
reads(k);
for(int i=; i<=k; i++)
//cin>>v[i];
reads(v[i]);
for(int i=; i<=n; i++)
for(int j=; j<=*k; j++)
//cin>>a[i][j];
reads(a[i][j]);
for(int i=; i<=k; i++)
while(!q[i].empty())
q[i].pop();
for(int i=; i<=n; i++)
q[].push(mp(a[i][],i));
int ans=;
fillchar(vis,);
while()
{
int flag=;
for(int i=; i<=k; i++)
{
while(!q[i].empty())
{
pii p=q[i].top();
if(v[i]<p.fi)
break;
else
vis[p.se]++;
if(vis[p.se]==k)
{
flag=;
for(int j=k+; j<=*k; j++)
v[j-k]+=a[p.se][j];
ans++;
}
else
{
q[i+].push(mp(a[p.se][i+],p.se));
}
q[i].pop();
}
}
if(flag)
break;
}
printf("%d\n",ans);
for(int i=; i<k; i++)
{
printf("%d ",v[i]);
}
printf("%d\n",v[k]);
}
}

HDU 6396 贪心+优先队列+读入挂的更多相关文章

  1. HDU 6044 Limited Permutation 读入挂+组合数学

    Limited Permutation Problem Description As to a permutation p1,p2,⋯,pn from 1 to n, it is uncomplica ...

  2. HDU 6396 Swordsman --------2018 Multi-University Training Contest 7 (模拟+读入挂)

    原题地址: 打怪升级 一开始有N个怪物:主角有K个能力:只有K个能力都击败怪物才能斩杀怪物并获得K个能力的增值:问最多能杀几个怪物: 做法: 用优先队列把怪物能力装进去:能力小放前面: 最重要的是数据 ...

  3. HDU 6438 网络赛 Buy and Resell(贪心 + 优先队列)题解

    思路:维护一个递增队列,如果当天的w比队首大,那么我们给收益增加 w - q.top(),这里的意思可以理解为w对总收益的贡献而不是真正获利的具体数额,这样我们就能求出最大收益.注意一下,如果w对收益 ...

  4. 牛客网 牛客练习赛43 C.Tachibana Kanade Loves Review-最小生成树(并查集+Kruskal)+建虚点+读入挂

    链接:https://ac.nowcoder.com/acm/contest/548/C来源:牛客网 Tachibana Kanade Loves Review 时间限制:C/C++ 2秒,其他语言4 ...

  5. hdu6396 /// fread()快速读入挂

    题目大意: 给定n k 给定主角具有的k种属性 给定n个怪兽具有的k种属性和打死该怪兽后能得到的k种属性对应增幅 求主角最多能打死多少怪兽和最终主角的k种属性 k最大为5 开5个优先队列贪心 快速读入 ...

  6. hihoCoder 1309:任务分配 贪心 优先队列

    #1309 : 任务分配 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 给定 N 项任务的起至时间( S1, E1 ), ( S2, E2 ), ..., ( SN,  ...

  7. UVA 11134 - Fabled Rooks(贪心+优先队列)

    We would like to place  n  rooks, 1 ≤  n  ≤ 5000, on a  n×n  board subject to the following restrict ...

  8. C. Playlist Educational Codeforces Round 62 (Rated for Div. 2) 贪心+优先队列

    C. Playlist time limit per test 2 seconds memory limit per test 256 megabytes input standard input o ...

  9. 读入挂(IO)

    快如闪电,清华杜瑜皓的读入挂,一模一样代码,加了这个之后... 细思极恐,and 整整行!!! namespace IO{ #define BUF_SIZE 100000 #define OUT_SI ...

随机推荐

  1. C# 移动控件

    最近要做车牌识别的,不同地区收费标准不一,所以想做个可以移动控件来给客户选择停车场收费条件的.   首先因为要自动排序控件选FlowLayoutPanel做容器,加若干Panel和FlowLayout ...

  2. HYSBZ 1503 郁闷的出纳员 (Splay树)

    题意: 作为一名出纳员,我的任务之一便是统计每位员工的工资.但是我们的老板反复无常,经常调整员工的工资.如果他心情好,就可能把每位员工的工资加上一个相同的量.反之,如果心情不好,就可能把他们的工资扣除 ...

  3. 插入insert几种用法

    1.insert ignore into 当插入数据时,如出现错误时,如重复数据,将不返回错误,只以警告形式返回.所以使用ignore请确保语句本身没有问题,否则也会被忽略掉.例如: INSERT I ...

  4. 【搜索】P1219 八皇后

    题目描述 检查一个如下的6 x 6的跳棋棋盘,有六个棋子被放置在棋盘上,使得每行.每列有且只有一个,每条对角线(包括两条主对角线的所有平行线)上至多有一个棋子. 上面的布局可以用序列2 4 6 1 3 ...

  5. 牛客OI赛制测试赛2(0906)

    牛客OI赛制测试赛2(0906) A :无序组数 题目描述 给出一个二元组(A,B) 求出无序二元组(a,b) 使得(a|A,b|B)的组数 无序意思就是(a,b)和(b,a) 算一组. 输入描述: ...

  6. POJ-1002-487-3279(字符串)

    487-3279 Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 309685 Accepted: 55292 Descripti ...

  7. fit in gnuplot

    Table of Contents 1. fit-gnuplot 1 fit-gnuplot syntax >> fit [xrange][yrange] function 'datafi ...

  8. CUDA & cuDNN环境配置

    环境 python3.5 tensorflow 1.3 VUDA  8.0 cuDNN V6.0 1.确保GPU驱动已经安装 lspci | grep -i nvidia 通过此命令可以查看GPU信息 ...

  9. 关于在Safari浏览器中将网页添加到主屏幕的相关设置(自定义图标,启动动画,自定义名称)

    在ios中我们可以使用Safari浏览自带的将网页添加到主屏幕上,让我们的web页面看起来像native那样 第一步: 第二步: 第三步: 到这里还没结束:我们还要进行相关设置才能使我们的应用更像原生 ...

  10. SSM整合shiro

    采用maven构建项目 1pom.xml中加入shiro依赖 <!-- shiro --> <dependency> <groupId>org.apache.shi ...