Swordsman —— 输入模板

本篇介绍了一个关于剑士Lawson通过不同魔法属性战胜怪物的算法问题。Lawson有k种魔法属性,面对n个怪物,每个怪物也有k种防御属性。如果Lawson的所有魔法属性都不低于对应怪物的防御属性,则可以击败该怪物并获得经验值提升魔法属性。文章探讨了如何最大化击败怪物的数量及魔法属性的方法。

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.

看了题解之后发现不是一道很难的题目,主要是输入的问题,普通的read()已经满足不了它了。
我们可以开优先队列或者set来存满足条件的数,一旦i满足,我们就把i+1存到下一个队列里面,这样一次一次操作就可以吧所有可能达到的都放到最后一个队列里,如果没有新的值进来就说明已经到循环尾声,break;

#include<bits/stdc++.h>
using namespace std;

namespace fastIO {
    #define BUF_SIZE 100000
    //fread -> read
    bool IOerror = 0;
    inline char nc() {
        static char buf[BUF_SIZE], *p1 = buf + BUF_SIZE, *pend = buf + BUF_SIZE;
        if(p1 == pend) {
            p1 = buf;
            pend = buf + fread(buf, 1, BUF_SIZE, stdin);
            if(pend == p1) {
                IOerror = 1;
                return -1;
            }
        }
        return *p1++;
    }
    inline bool blank(char ch) {
        return ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t';
    }
    inline void read(int &x) {
        char ch;
        while(blank(ch = nc()));
        if(IOerror) return;
        for(x = ch - '0'; (ch = nc()) >= '0' && ch <= '9'; x = x * 10 + ch - '0');
    }
    #undef BUF_SIZE
};
using namespace fastIO;

#define pa pair<int,int>
#define mp(a,b) make_pair(a,b)
priority_queue<pa,vector<pa>, greater<pa> >Q[15];
int def[100005][15],add[100005][15];
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n,k;
        int s[15];
        read(n),read(k);
        priority_queue<pa,vector<pa>, greater<pa> >Q[15];
        for(int i=1;i<=k;i++)
            read(s[i]);
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=k;j++)
                read(def[i][j]);
            Q[1].push({def[i][1],i});
            for(int j=1;j<=k;j++)
                read(add[i][j]);
        }
        int ans=0;
        while(1)
        {
            int lastans=ans;
            for(int i=1;i<k;i++)
            {
                while(!Q[i].empty()&&Q[i].top().first<=s[i])
                {
                    int pos=Q[i].top().second;
                    Q[i].pop();
                    Q[i+1].push({def[pos][i+1],pos});

                }
            }
            while(!Q[k].empty()&&Q[k].top().first<=s[k])
            {
                int pos=Q[k].top().second;
                Q[k].pop();
                ans++;
                for(int i=1;i<=k;i++)
                    s[i]+=add[pos][i];
            }
            if(ans==lastans)
                break;
        }
        printf("%d\n",ans);
        for(int i=1;i<=k;i++)
            printf("%d%c",s[i],i==k?'\n':' ');
    }
    return 0;
}
乐播投屏是一款简单好用、功能强大的专业投屏软件,支持手机投屏电视、手机投电脑、电脑投电视等多种投屏方式。 多端兼容与跨网投屏:支持手机、平板、电脑等多种设备之间的自由组合投屏,且无需连接 WiFi,通过跨屏技术打破网络限制,扫一扫即可投屏。 广泛的应用支持:支持 10000+APP 投屏,包括综合视频、网盘与浏览器、美韩剧、斗鱼、虎牙等直播平台,还能将央视、湖南卫视等各大卫视的直播内容一键投屏。 高清流畅投屏体验:腾讯独家智能音画调校技术,支持 4K 高清画质、240Hz 超高帧率,低延迟不卡顿,能为用户提供更高清、流畅的视觉享受。 会议办公功能强大:拥有全球唯一的 “超级投屏空间”,扫码即投,无需安装。支持多人共享投屏、远程协作批注,PPT、Excel、视频等文件都能流畅展示,还具备企业级安全加密,保障会议资料不泄露。 多人互动功能:支持多人投屏,邀请好友加入投屏互动,远程也可加入。同时具备一屏多显、语音互动功能,支持多人连麦,实时语音交流。 文件支持全面:支持 PPT、PDF、Word、Excel 等办公文件,以及视频、图片等多种类型文件的投屏,还支持网盘直投,无需下载和转格式。 特色功能丰富:投屏时可同步录制投屏画面,部分版本还支持通过触控屏或电视端外接鼠标反控电脑,以及在投屏过程中用画笔实时标注等功能。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值