分宿舍

http://acm.hdu.edu.cn/showproblem.php?pid=6492
贪心

枚举情侣房间数,然后我们考虑剩下的人的情况分情况讨论d1和d2,
(注意尽量不空房间会节省资金)

一开始认为可以直接%6取余,分情况讨论余数的分配,但后来发现仍然有情况没有考虑到,比如有七个人,2,2,3的这种情况就无法考虑到

题解说暴力也可以过题,but不会暴力,只会TLE

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF=1e18;

int main()
{
	int t;
	scanf("%d",&t);
	long long n,m,k,a,b,c;
	long long cost=INF;
	long long temp1,temp2;
	long long n1,n2;
	double d1,d2;
	while(t--)
	{
    cost=INF;
		scanf("%lld %lld %lld %lld %lld %lld",&n,&m,&k,&a,&b,&c);
		d1=a*1.0/2;
        d2=b*1.0/3;
		for(int i=0;i<=k;i++)
		{
			n1=n+k-i;
			n2=m+k-i;
			if(d1>d2)//min(n*b,(n-1)*b+a,(n-2)*b+2*a)尽量使用空间
			{
				temp1=min((ll)ceil(n1*1.0/3)*b,n1/3*b+(ll)ceil((n1%3)*1.0/2)*a);
				temp2=min((ll)ceil(n2*1.0/3)*b,n2/3*b+(ll)ceil((n2%3)*1.0/2)*a);
				if(n1>=4)
				{
					n1-=4;
					temp1=min(temp1,(ll)ceil(n1*1.0/3)*b+2*a);
				}
				if(n2>=4)
				{
					n2-=4;
					temp2=min(temp2,(ll)ceil(n2*1.0/3)*b+2*a);
				}
			}
			else//min(n*a,(n-2)*a+b)
			{
				if(n1%2==0||n1<=1)
					temp1=(ll)ceil(n1*1.0/2)*a;
				else
					temp1=min((ll)ceil(n1*1.0/2)*a,(ll)ceil((n1-3)*1.0/2)*a+b);
				if(n2%2==0||n2<=1)
					temp2=(ll)ceil(n2*1.0/2)*a;
				else
                temp2=min((ll)ceil(n2*1.0/2)*a,(ll)ceil((n2-3)*1.0/2)*a+b);
			}
			cost=min(cost,temp1+temp2+i*c);
		}
		printf("%lld\n",cost);
	}
	return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值