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. 软件综合实践Axure介绍

    首先就是下载安装Axure这款软件了,在百度上搜索“”Axure rp下载“”即可,下载完成后,打开exe安装,根据步骤一步步点击下一步即可完成安装. 运行该软件时会出现类似于填写激活码的东西,这时依 ...

  2. keras用法

    关于Keras的“层”(Layer) 所有的Keras层对象都有如下方法: layer.get_weights():返回层的权重(numpy array) layer.set_weights(weig ...

  3. C++ STL标准容器插入删除算法的复杂度

    1 vector内部实现: 数组 // 就是没有固定大小的数组,vector直接翻译是向量的意思支持操作:begin(), //取首个元素,返回一个iteratorend(), //取末尾(最后一个元 ...

  4. flask、tornado、BaseHTTPServer性能简单对比

    最近写了一个web应用,分别用flask.tornado.BaseHTTPServer都实现了一次,顺便就对比了一下三者的性能,本结果仅对本次测试负责(这句话很内涵,值得推广). 测试工具用了ab,时 ...

  5. java窗体

    听完老师所讲的窗体,然后自己就去尝试写代码,结果是窗体出现了,但是就是不能关闭,求解!! package Swing.src.swring; import java.awt.Color;import ...

  6. @Override报错的处理

    有时候我们从SVN导的项目,jre和jar包都没问题,但是就会出如下图的错误: xi 点击红叉,显示错误信息如下: 点击工具里面的window-->preferences-->java-- ...

  7. Pycharm,Python 安装OpenCV and CV2 时,报错,教你如何正确安装。

    Collecting cv2 Could not find a version that satisfies the requirement cv2 (from versions: ) No matc ...

  8. linux准备工具VMware以及ubuntu

    链接:https://pan.baidu.com/s/1j7DZCmzOcC2rPAciHtZgkA 密码:et5s

  9. jQuary学习の五のAJAX

    AJAX 是与服务器交换数据的技术,它在不重载全部页面的情况下,实现了对部分网页的更新. 一.jQuery load() 方法 jQuery load() 方法是简单但强大的 AJAX 方法. loa ...

  10. Node.js进程内存使用查看方法及返回对象的含义

    1 前言 使用process.memoryUsage() ,然后可以得到一个对象如下: var mem = process.memoryUsage(); console.log(mem); 结果: { ...