// by BNU_LZM
#include<cstdio>
#include<queue>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
struct node
{
int v[3], d;
bool operator < (const node &rhs) const
{
return d > rhs.d;
}
};
int t, cap[3], ans[210], vis[210][210];
priority_queue<node> q;
void check(node u)
{
for(int i = 0; i < 3; i++)
{
int r = u.v[i];
if(ans[r] < 0 || ans[r] > u.d) ans[r] = u.d;
}
}
int main()
{
int a, b, c;
cin >> a >> b >> c >> t;
cap[0] = a; cap[1] = b; cap[2] = c;
memset(ans, -1, sizeof(ans));
node start;
start.d = 0;
start.v[0] = 0; start.v[1] = 0; start.v[2] = c;
memset(vis, 0, sizeof(vis));
vis[0][0] = 1;
q.push(start);
while(!q.empty())
{
node u = q.top(); q.pop();
check(u);
if(ans[t] > 0) break;
for(int i = 0; i < 3; i++)
{
for(int j = 0; j < 3; j++)
{
if(i == j || u.v[j] == cap[j] || !u.v[i]) continue;
int amount = min(u.v[i], cap[j]-u.v[j]);
node newu = u;
newu.d += amount;
newu.v[i] -= amount;
newu.v[j] += amount;
if(!vis[newu.v[0]][newu.v[1]])
{
vis[newu.v[0]][newu.v[1]] = 1;
q.push(newu);
}
}
}
}
while(t)
{
if(ans[t]) {printf("%d %d\n", t, ans[t]); break;}
else t--;
}
return 0;
}
倒水问题
最新推荐文章于 2024-05-31 10:30:00 发布