Swordsman

Time Limit: / MS (Java/Others)    Memory Limit: / K (Java/Others)
Total Submission(s): Accepted Submission(s): 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,,ai,,ai,,…,ai,k. If v1≥ai, and v2≥ai, and v3≥ai, 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=,,,…,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 (≤n≤,≤k≤).
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,,ai,,ai,,…,ai,k,bi,,bi,,bi,,…,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 ≤×.
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′,v′,v′,…,v′k and the i-th integer means maximum of the i-th magic attibute. Sample Input Sample Output Hint For the sample, initial V = [, , ]
① kill monster # (, , ), V + [, , ] = [, , ]
② kill monster # (, , ), V + [, , ] = [, , ]

对于 k 种防御属性,分开进行从小到大排序,设立 k 个指针从最小处开始往最大处移动,对满足被杀死的条件的属 性进行标记

,当某只 monster 的所有防御属性都被标记时,更新剑士的魔法属性同时更新指针往后移动。时间复 杂度 O(kn log n)

#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
struct node{
int val;
int id;
}a[][];
int b[][];
int sum[];
bool cmp(node p,node q)
{
return p.val<q.val;
}
#define fi(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 ;
}
};
int main()
{
int t;
fi(t);
while(t--)
{
int n,m;
fi(n);
fi(m);
memset(sum,,sizeof sum);
int pq[];
for(int i=;i<=m;i++)
{
fi(pq[i]);
}
for(int i=;i<=n;i++)
{
for(int j=;j<=m;j++)
{
fi(a[j][i].val);
a[j][i].id = i;
}
for(int j=;j<=m;j++)
fi(b[j][i]);
}
for(int i=;i<=m;i++)
sort(a[i]+,a[i]++n,cmp);
int zhizhen[]={,,,,,};
int pppp=;
while()
{
int pp=;
for(int i=;i<=m;i++)
{
while(a[i][zhizhen[i]].val<=pq[i]&&zhizhen[i]<=n)
{ sum[a[i][zhizhen[i]].id]++;
if(sum[a[i][zhizhen[i]].id]==m)
{
pp++;
pppp++;
for(int j=;j<=m;j++)
{
pq[j]+=b[j][a[i][zhizhen[i]].id]; }
}
zhizhen[i]++; }
}
if(pp==)
break; }
cout<<pppp<<endl;
for(int i=;i<=m;i++)
{ if(i!=)
cout<<" ";
cout<<pq[i];
}
cout<<endl; } return ;
}

hdu6396(思维+输入挂)的更多相关文章

  1. 【libreOJ模板】并查集(输入挂,取模与find优化)

    1.了解了各种输入挂性orz,找到了一个合适的 2.find用while写能快一倍,并且能被数据卡掉 3.取模只能快十几毫秒,但也能被数据卡掉 取模find双优化是1997mm过的 再加一个性价比较高 ...

  2. ACM的奇计淫巧_输入挂

    什么是输入挂? 众所周知scanf比cin快的多,那么有没有比scanf更快的东西呢?答案就是输入挂,输入挂利用了告诉读取的函数getchar(),然后再人工处理成整数或浮点,比使用scanf快太多. ...

  3. 【7-9 有重复的数据I (20 分)】【此题卡输入,需要自己写个输入挂】

    参考一个博客的输入挂,先挂在此处,以备以后使用. import java.io.*; import java.util.*; import java.math.*; public class Main ...

  4. [hdu5392 Infoplane in Tina Town]置换的最小循环长度,最小公倍数取模,输入挂

    题意:给一个置换,求最小循环长度对p取模的结果 思路:一个置换可以写成若干循环的乘积,最小循环长度为每个循环长度的最小公倍数.求最小公倍数对p取模的结果可以对每个数因式分解,将最小公倍数表示成质数幂的 ...

  5. HDU6396 (贪心+fread 挂)

    题意:初始值你有k个属性的攻击vi,有n个怪兽,每个怪兽有k种属性的血量ai,并且有k种属性的加成bi,当你的k种属性的值全部大于等于某只怪兽的k种属性的血量,你可以杀死他,并且你的攻击力vi会升级, ...

  6. hdu 6205: card card card【输入挂】

    题目链接 感谢 http://blog.csdn.net/txgang/article/details/77568491 以下供参考 getchar读入法 2683MS FastIO法 MX=1e2 ...

  7. hdu 6044 : Limited Permutation (2017 多校第一场 1012) 【输入挂 组合数学】

    题目链接 参考博客: http://blog.csdn.net/jinglinxiao/article/details/76165353 http://blog.csdn.net/qq_3175920 ...

  8. ACM输入外挂

    一.什么是输入挂 scanf的输入速度不cin快得多,那么有没有比scanf更快的东西呢?这就是要用到输入挂了. 二.什么时候使用输入挂 当输入规模达到1x10^6次方的时候,就需要输入挂,否则很可能 ...

  9. hdu-5992 Finding Hotels(kd-tree)

    题目链接: Finding Hotels Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 102400/102400 K (Java/ ...

随机推荐

  1. python-布尔表达式

    1.布尔类型(bool): 1.只有两种情况  真/假 (True /  False) 2. print(type(False))      # <class 'bool'> type() ...

  2. 解决mysql连接报“Communications link failure”错误

    <!--定义在从数据库获取新连接失败后重复尝试的次数.默认值: 30 :小于等于0表示无限次--> <property name="acquireRetryAttempts ...

  3. CCF CSP 201312-2 ISBN号码

    题目链接:http://118.190.20.162/view.page?gpid=T4 问题描述 试题编号: 201312-2 试题名称: ISBN号码 时间限制: 1.0s 内存限制: 256.0 ...

  4. Docker初始

    如今Docker的使用已经非常普遍,特别在一线互联网公司.使用Docker技术可以帮助企业快速水平扩展服务,从而到达弹性部署业务的能力.在云服务概念兴起之后,Docker的使用场景和范围进一步发展,如 ...

  5. lnmp 系统500 报错

    分析点: 1 文件目录权限不足 如果日志缓存目录没有写入权限 chmod -R 775 目录 2 lnmp 一键安装包 查看.user.ini ,其中open_basedir  不要设置到public ...

  6. deno深入揭秘及未来展望

    deno node.js之父Ryan Dahl在一个月前发起了名为deno的项目,项目的初衷是打造一个基于v8引擎的安全的TypeScript运行时,同时实现HTML5的基础API.所谓的安全运行时, ...

  7. Bugku-CTF之过狗一句话(送给大家一个过狗一句话)

    Day25 过狗一句话   http://123.206.87.240:8010/ 送给大家一个过狗一句话<?php $poc="a#s#s#e#r#t"; $poc_1=e ...

  8. 顺手写一下HTTP协议

    本文目录 一 什么是HTTP协议 二 Http的特点 三 Http报文 回到目录 一 什么是HTTP协议 HTTP协议是Hyper Text Transfer Protocol(超文本传输协议)的缩写 ...

  9. Linux下复制文件

    命令: cp -Rf /文件名1/*               /文件名2 把文件夹1下的文件复制到文件2中(/* 表示复制文件夹1下的文件,不复制文件夹1)

  10. FJNU Fang G and his Friends(状压DP)题解

    Description     众所周知,fang G 有很多小伙伴,有一天,Fang G 打算带他们去玩有趣的游戏OOXX,这个游戏需要分成两组,有趣的是,每个人互相之间都有一个满意度,大家都想和自 ...