HDU 6396 贪心+优先队列+读入挂
Swordsman
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 2587 Accepted Submission(s): 791
Now we want to know how many monsters Lawson can kill at most and how much Lawson's magic attributes can be maximized.
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.
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.
For the sample, initial V = [7, 1, 1]
because 23 < 24.
解析 策略当然是先选最小的符合条件的在一步一步扩大,所以我们就借助优先队列来解决,把上一个满足属性条件的怪兽 转移到下一个优先队列 然后当它被标记为了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 贪心+优先队列+读入挂的更多相关文章
- HDU 6044 Limited Permutation 读入挂+组合数学
Limited Permutation Problem Description As to a permutation p1,p2,⋯,pn from 1 to n, it is uncomplica ...
- HDU 6396 Swordsman --------2018 Multi-University Training Contest 7 (模拟+读入挂)
原题地址: 打怪升级 一开始有N个怪物:主角有K个能力:只有K个能力都击败怪物才能斩杀怪物并获得K个能力的增值:问最多能杀几个怪物: 做法: 用优先队列把怪物能力装进去:能力小放前面: 最重要的是数据 ...
- HDU 6438 网络赛 Buy and Resell(贪心 + 优先队列)题解
思路:维护一个递增队列,如果当天的w比队首大,那么我们给收益增加 w - q.top(),这里的意思可以理解为w对总收益的贡献而不是真正获利的具体数额,这样我们就能求出最大收益.注意一下,如果w对收益 ...
- 牛客网 牛客练习赛43 C.Tachibana Kanade Loves Review-最小生成树(并查集+Kruskal)+建虚点+读入挂
链接:https://ac.nowcoder.com/acm/contest/548/C来源:牛客网 Tachibana Kanade Loves Review 时间限制:C/C++ 2秒,其他语言4 ...
- hdu6396 /// fread()快速读入挂
题目大意: 给定n k 给定主角具有的k种属性 给定n个怪兽具有的k种属性和打死该怪兽后能得到的k种属性对应增幅 求主角最多能打死多少怪兽和最终主角的k种属性 k最大为5 开5个优先队列贪心 快速读入 ...
- hihoCoder 1309:任务分配 贪心 优先队列
#1309 : 任务分配 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 给定 N 项任务的起至时间( S1, E1 ), ( S2, E2 ), ..., ( SN, ...
- UVA 11134 - Fabled Rooks(贪心+优先队列)
We would like to place n rooks, 1 ≤ n ≤ 5000, on a n×n board subject to the following restrict ...
- 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 ...
- 读入挂(IO)
快如闪电,清华杜瑜皓的读入挂,一模一样代码,加了这个之后... 细思极恐,and 整整行!!! namespace IO{ #define BUF_SIZE 100000 #define OUT_SI ...
随机推荐
- ios app跳转拨打电话界面,调用拨打电话功能
DNLogFUNC //两种方法都可以用 //这种据说是可以上appstore NSURL *phoneURL = [NSURL URLWithString:[NSString stringWithF ...
- java中同步(synchronized)详解
一.开山篇: 1.synchronized的使用 一个程序中,如果该类中的代码可能运行于多线程环境下,那么就要考虑同步的问题.在Java中内置了语言级的同步原语--synchronized,这也大大简 ...
- SQLite – LIMIT子句
SQLite - LIMIT子句 SQLite LIMIT子句是用来限制SELECT语句返回的数据量. 语法: SELECT语句.LIMIT子句的基本语法如下: SELECT column1, col ...
- PHP 中空字符串介绍0、null、empty和false之间的关系
0是数字,是empty,是false,不是null,值相当于空字符串,但类型不是字符串,去空格或强制转换为字符串型时不等于空字符串 ""的值相当于0,是empty,是空字符串,是f ...
- v8引擎详解
引用网址: https://blog.csdn.net/swimming_in_it_/article/details/78869549 前言 JavaScript绝对是最火的编程语言之一,一直具有很 ...
- SQL Server 2008 空间数据存储摘抄(SRID 点 MultiPoint LineString MultiLineString 多边形 MultiPolygon GeometryCollection)
有两种类型的空间数据.geometry 数据类型支持平面或欧几里得(平面球)数据.geometry 数据类型符合适用于 SQL 规范的开放地理空间联盟 (OGC) 简单特征 1.1.0 版. 另外,S ...
- django insert data into mysql
#!/usr/bin/python # -*- coding:utf-8 -*- # @filename: search # @author:wwx399777 wuweiji # @date: 20 ...
- 框模型中设置内容区域元素占地尺寸box-sizing属性
盒子模型有两种 一种是 内容盒子模型(content-box)一种是边框盒子模型(border-box). content-box:设置的尺寸,只设置内容区域, 左外边距+左边框+左内边距+内容区域宽 ...
- 【MyBatis】MyBatis Tomcat JNDI原理及源码分析
一. Tomcat JNDI JNDI(java nameing and drectory interface),是一组在Java应用中访问命名和服务的API,所谓命名服务,即将对象和名称联系起来,使 ...
- Jenkins中部署Sonar代码检查
1 安装并启动sonarqube docker pull sonarqube:7.5-community docker run \ --name sonarqube \ --network ci \ ...