#include<bits/stdc++.h>
using namespace std;
const int maxn=200+50;
int ans[maxn];
int cap[3],t,a,b,c,d;
int v[maxn][maxn];
struct point
{
int v[3],dist;
bool operator < (const point& rhs) const
{
return rhs.dist<dist;
}
};
void update(point u)
{
for(int i=0; i<3; i++)
if(ans[u.v[i]]<0||u.dist<ans[u.v[i]])
ans[u.v[i]]=u.dist;
}
void solve(int a,int b,int c,int d)
{
point start;
memset(v,0,sizeof(v));
memset(ans,-1,sizeof(ans));
priority_queue<point> q;
cap[0]=a;
cap[1]=b;
cap[2]=c;
start.v[0]=0;
start.v[1]=0;
start.v[2]=c;
start.dist=0;
v[0][0]=1;
q.push(start);
while(!q.empty())
{
point now=q.top();
q.pop();
update(now);
if(ans[d]>=0) break;
for(int i=0; i<3; i++)
for(int j=0; j<3; j++)
{
if(i!=j)
{
if(now.v[i]==0||now.v[j]==cap[j]) continue;
int sum=min(cap[j],now.v[i]+now.v[j])-now.v[j];
point next;
memcpy(&next,&now,sizeof(now));
next.v[i]-=sum;
next.v[j]+=sum;
next.dist+=sum;
if(!v[next.v[0]][next.v[1]])
{
v[next.v[0]][next.v[1]]=1;
q.push(next);
}
}
}
}
while(d>=0)
{
if(ans[d]>=0)
{
printf("%d %d\n",ans[d],d);
break;
}
d--;
}
}
int main()
{
scanf("%d",&t);
while(t--)
{
scanf("%d%d%d%d",&a,&b,&c,&d);
solve(a,b,c,d);
}
return 0;
}
UVA 10603(p202)----Fill
最新推荐文章于 2024-07-06 08:24:20 发布