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;
}