UVa10603

竟然直接暴力广搜过了。

#include <iostream>
#include <cstdio>
#include <queue>
#include <cstring>
#include <map>
#include <algorithm>
using namespace std;

int vstd[205][205][205];

struct bottle
{
	int a,b,c;
};

int main()
{
	int T;
	int a,b,c,d;
	scanf("%d",&T);
	while (T--)
	{
		struct bottle B;
		scanf("%d%d%d%d",&a,&b,&c,&d);
		B.a=B.b=0;
		B.c=c;

    memset(vstd,0,sizeof(vstd));
		queue<struct bottle> Q;
		queue<int> water;
		Q.push(B);
		water.push(0);
		vstd[0][0][c]=1;

		int minn=1000000000;
		int minnwater;
		int record=1000000000;
		int find=0;

		while (!Q.empty())
		{
			struct bottle front=Q.front();
			if ( front.a==d || front.b==d || front.c==d)
			{
				if (!find)
				  minnwater=water.front();
				else if (water.front()<minnwater)
					minnwater=water.front();
				record=d;
				find=1;
			}
			else if (!find)
			{
				if (front.a<d && d-front.a<minn)
				{
					minn=d-front.a;
					record=front.a;
					minnwater=water.front();
				}
				if (front.b<d && d-front.b<minn)
				{
					minn=d-front.b;
					record=front.b;
					minnwater=water.front();
				}
				if (front.c<d && d-front.c<minn)
				{
					minn=d-front.c;
					record=front.c;
					minnwater=water.front();
				}
			}

			int temp=front.a;
			int temp2=front.b;
			front.b+=front.a;
			front.a=0;
			if (front.b>b)
			{
				front.a=temp-(b-temp2);
				front.b=b;
				temp-=front.a;
			}
			if (!vstd[front.a][front.b][front.c])
			{
				Q.push(front);
				water.push(water.front()+temp);
				vstd[front.a][front.b][front.c]=1;
			}

			front=Q.front();
			temp=front.a;
			temp2=front.c;
			front.c+=front.a;
			front.a=0;
			if (front.c>c)
			{
				front.a=temp-(c-temp2);
				front.c=c;
				temp-=front.a;
			}
			if (!vstd[front.a][front.b][front.c])
			{
				Q.push(front);
				water.push(water.front()+temp);
				vstd[front.a][front.b][front.c]=1;
			}

			front=Q.front();
			temp=front.b;
			temp2=front.a;
			front.a+=front.b;
			front.b=0;
			if (front.a>a)
			{
				front.b=temp-(a-temp2);
				front.a=a;
				temp-=front.b;
			}
			if (!vstd[front.a][front.b][front.c])
			{
				Q.push(front);
				water.push(water.front()+temp);
				vstd[front.a][front.b][front.c]=1;
			}

			front=Q.front();
			temp=front.b;
			temp2=front.c;
			front.c+=front.b;
			front.b=0;
			if (front.c>c)
			{
				front.b=temp-(c-temp2);
				front.c=c;
				temp-=front.b;
			}
			if (!vstd[front.a][front.b][front.c])
			{
				Q.push(front);
				water.push(water.front()+temp);
				vstd[front.a][front.b][front.c]=1;
			}

			front=Q.front();
			temp=front.c;
			temp2=front.a;
			front.a+=front.c;
			front.c=0;
			if (front.a>a)
			{
				front.c=temp-(a-temp2);
				front.a=a;
				temp-=front.c;
			}
			if (!vstd[front.a][front.b][front.c])
			{
				Q.push(front);
				water.push(water.front()+temp);
				vstd[front.a][front.b][front.c]=1;
			}

			front=Q.front();
			temp=front.c;
			temp2=front.b;
			front.b+=front.c;
			front.c=0;
			if (front.b>b)
			{
				front.c=temp-(b-temp2);
				front.b=b;
				temp-=front.c;
			}
			if (!vstd[front.a][front.b][front.c])
			{
				Q.push(front);
				water.push(water.front()+temp);
				vstd[front.a][front.b][front.c]=1;
			}

			Q.pop();
			water.pop();
		}

		printf("%d %d\n",minnwater,record);
	}
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值