Swordsman HDU - 6396

http://acm.hdu.edu.cn/showproblem.php?pid=6396

开五个堆 分别以某一个a值排序 满足一个当前a值就推入下一个堆 然后在随后一个堆把所有符合条件的怪兽的b值加到v上 然后再从头扫第一个堆

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

struct node0
{
    int a[6];
    int b[6];
};

struct node1
{
    bool friend operator < (node1 n1,node1 n2)
    {
        return n1.a[1]>n2.a[1];
    }
    int a[6];
    int b[6];
};

struct node2
{
    bool friend operator < (node2 n1,node2 n2)
    {
        return n1.a[2]>n2.a[2];
    }
    int a[6];
    int b[6];
};

struct node3
{
    bool friend operator < (node3 n1,node3 n2)
    {
        return n1.a[3]>n2.a[3];
    }
    int a[6];
    int b[6];
};

struct node4
{
    bool friend operator < (node4 n1,node4 n2)
    {
        return n1.a[4]>n2.a[4];
    }
    int a[6];
    int b[6];
};

struct node5
{
    bool friend operator < (node5 n1,node5 n2)
    {
        return n1.a[5]>n2.a[5];
    }
    int a[6];
    int b[6];
};

node0 mon[100010];
priority_queue <node1> que1;
priority_queue <node2> que2;
priority_queue <node3> que3;
priority_queue <node4> que4;
priority_queue <node5> que5;
int v[10];
int n,k;

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;

int main()
{
    node1 cur1;
    node2 cur2;
    node3 cur3;
    node4 cur4;
    node5 cur5;
    int t,i,j,cnt,ans;
    //scanf("%d",&t);
    read(t);
    while(t--)
    {
        //scanf("%d%d",&n,&k);
        read(n);
        read(k);
        for(i=1;i<=k;i++)
        {
            //scanf("%d",&v[i]);
            read(v[i]);
        }
        for(i=1;i<=n;i++)
        {
            for(j=1;j<=k;j++)
            {
                //scanf("%d",&mon[i].a[j]);
                read(mon[i].a[j]);
            }
            for(j=1;j<=k;j++)
            {
                //scanf("%d",&mon[i].b[j]);
                read(mon[i].b[j]);
            }
        }

        while(!que1.empty()) que1.pop();
        while(!que2.empty()) que2.pop();
        while(!que3.empty()) que3.pop();
        while(!que4.empty()) que4.pop();
        while(!que5.empty()) que5.pop();
        for(i=1;i<=n;i++)
        {
            for(j=1;j<=k;j++)
            {
                cur1.a[j]=mon[i].a[j];
                cur1.b[j]=mon[i].b[j];
            }
            que1.push(cur1);
        }

        cnt=0,ans=0;
        while(1)
        {
            if(cnt%k==0)
            {
                while(!que1.empty())
                {
                    cur1=que1.top();
                    if(cur1.a[1]<=v[1])
                    {
                        que1.pop();
                        if(k>1)
                        {
                            for(i=1;i<=k;i++)
                            {
                                cur2.a[i]=cur1.a[i];
                                cur2.b[i]=cur1.b[i];
                            }
                            que2.push(cur2);
                        }
                        else
                        {
                            for(i=1;i<=k;i++) v[i]+=cur1.b[i];
                            ans++;
                        }
                    }
                    else break;
                }
            }
            else if(k>=2&&cnt%k==1)
            {
                while(!que2.empty())
                {
                    cur2=que2.top();
                    if(cur2.a[2]<=v[2])
                    {
                        que2.pop();
                        if(k>2)
                        {
                            for(i=1;i<=k;i++)
                            {
                                cur3.a[i]=cur2.a[i];
                                cur3.b[i]=cur2.b[i];
                            }
                            que3.push(cur3);
                        }
                        else
                        {
                            for(i=1;i<=k;i++) v[i]+=cur2.b[i];
                            ans++;
                        }
                    }
                    else break;
                }
            }
            else if(k>=3&&cnt%k==2)
            {
                while(!que3.empty())
                {
                    cur3=que3.top();
                    if(cur3.a[3]<=v[3])
                    {
                        que3.pop();
                        if(k>3)
                        {
                            for(i=1;i<=k;i++)
                            {
                                cur4.a[i]=cur3.a[i];
                                cur4.b[i]=cur3.b[i];
                            }
                            que4.push(cur4);
                        }
                        else
                        {
                            for(i=1;i<=k;i++) v[i]+=cur3.b[i];
                            ans++;
                        }
                    }
                    else break;
                }
            }
            else if(k>=4&&cnt%k==3)
            {
                while(!que4.empty())
                {
                    cur4=que4.top();
                    if(cur4.a[4]<=v[4])
                    {
                        que4.pop();
                        if(k>4)
                        {
                            for(i=1;i<=k;i++)
                            {
                                cur5.a[i]=cur4.a[i];
                                cur5.b[i]=cur4.b[i];
                            }
                            que5.push(cur5);
                        }
                        else
                        {
                            for(i=1;i<=k;i++) v[i]+=cur4.b[i];
                            ans++;
                        }
                    }
                    else break;
                }
            }
            else if(k>=5&&cnt%k==4)
            {
                while(!que5.empty())
                {
                    cur5=que5.top();
                    if(cur5.a[5]<=v[5])
                    {
                        que5.pop();
                        for(i=1;i<=k;i++) v[i]+=cur5.b[i];
                        ans++;
                    }
                    else break;
                }
            }
            if(cnt>50*n) break;
            cnt++;
        }
        printf("%d\n",ans);
        for(i=1;i<=k;i++)
        {
            printf("%d",v[i]);
            if(i<k) printf(" ");
            else printf("\n");
        }
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/sunyutian1998/article/details/81662398