【链接】 我是链接,点我呀:)

【题意】

在这里输入题意

【题解】

三维显然可以缩短为2维。
只要知道a,b瓶中的水量,c瓶中的水量减一下就能得到。
则设dis[a][b]表示a,b瓶中水量为a,b时,水量的移动量。
然后做一下二维的spfa.
最后枚举a,b得到对应答案就好。

【代码】

/*
1.Shoud it use long long ?
2.Have you ever test several sample(at least therr) yourself?
3.Can you promise that the solution is right? At least,the main ideal
4.use the puts("") or putchar() or printf and such things?
5.init the used array or any value?
6.use error MAX_VALUE?
7.use scanf instead of cin/cout?
8.whatch out the detail input require
*/
#include <bits/stdc++.h>
using namespace std; const int N = 200; int bo[N+10][N+10];
bool inq[N+10][N+10]; int T,d,tot;
queue <pair<int,int> > dl;
int maxv[3]; int main(){
#ifdef LOCAL_DEFINE
freopen("F:\\c++source\\rush_in.txt", "r", stdin);
#endif
ios::sync_with_stdio(0),cin.tie(0);
cin >> T;
while (T--){
memset(inq,0,sizeof inq);
memset(bo,-1,sizeof bo);
for (int i = 0;i < 3;i++) cin >> maxv[i];cin >> d;
tot = maxv[2]; bo[0][0] = 0;
inq[0][0] = true;
dl.push(make_pair(0,0));
vector <int> v;v.resize(3);
while (!dl.empty()){
pair<int,int> temp = dl.front();dl.pop();
v[0] = temp.first,v[1] = temp.second,v[2] = tot-v[0]-v[1];
inq[v[0]][v[1]] = false;
for (int i = 0;i < 3;i++)
for (int j = 0;j < 3;j++)
if (i!=j){
//i->j
if (v[i]==0 || v[j]==maxv[j]) continue;
int ta = v[0],tb = v[1];
int temp = min(maxv[j]-v[j],v[i]);
v[i]-=temp,v[j]+=temp;
int a = v[0],b = v[1];
if (bo[a][b]==-1 || bo[a][b] > bo[ta][tb] + temp){
bo[a][b] = bo[ta][tb] + temp;
if (!inq[a][b]){
inq[a][b] = true;
dl.push(make_pair(a,b));
}
}
v[i]+=temp,v[j]-=temp;
} }
int now = 3000,usage = -1;
for (int i = 0;i <= maxv[0];i++)
for(int j = 0;j <= maxv[1];j++)
if (bo[i][j]!=-1){
v[0] = i,v[1] = j,v[2] = tot-i-j;
for (int k = 0;k < 3;k++){
int x = v[k];
if (x <= d){
if (now==3000 || x > now){
now = x;
usage = bo[i][j];
}else if (x==now){
usage = min(usage,bo[i][j]);
}
}
}
}
cout << usage <<' '<<now<<endl;
}
return 0;
}

【例题 7-8 UVA - 10603】Fill的更多相关文章

  1. UVa 10603 Fill [暴力枚举、路径搜索]

    10603 Fill There are three jugs with a volume of a, b and c liters. (a, b, and c are positive intege ...

  2. 【路径寻找问题】UVa 10603 - Fill

    如家大神书上的例题.第一次接触也是按代码敲得.敲的过程感觉很直观.但自己写估计会写的乱七八糟.以后不能砍得难就不愿意做这种题.否则只能做一些水题了.(PS:48) 紫书 #include<ios ...

  3. UVA 10603 Fill(正确代码尽管非常搓,网上很多代码都不能AC)

    题目链接:option=com_onlinejudge&Itemid=8&page=show_problem&problem=1544">click here~ ...

  4. UVA 10603 - Fill BFS~

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&c ...

  5. UVA 10603 Fill

    题意: 题目的意思是倒水,给出的四个数据是第一个水杯,第二个水杯,第三个水杯,和目标水量.一开始只有第三个水杯是满的,剩下的水杯是空的.倒水的时候只能把倒水出来的这个杯子倒空,或是倒水进去的杯子倒满. ...

  6. UVa 10603 Fill (暴力BFS+优先队列)

    题意:给定4个数,a,b,c,d,分别代表空杯子容积为a,b,一个盛满水的杯子容积为c,让你不断倒水,找一个dd,是不是存在某个时刻, 某个杯子里的水dd,和d相同,或者无限接近.让求最少的倒水量和d ...

  7. UVA - 10603 Fill(隐式图搜索)

    题目大意:经典的倒水问题. 给你三个瓶子,体积为a,b,c. 刚開始a.b是空的,c是满的,如今要求你到出体积为d的水.倒水的规则为,要么倒水方为空,要么接水方满 问倒到容量为d时,倒水的最小体积是多 ...

  8. UVA - 10603 Fill(BFS求最小值问题)

    题目: 给出三个杯子(没有刻度线)的容量,起初之后第三个杯子是满的,其他的两个杯子是空的,容量分别是a.b.c.问最少需要倒多少升水才能让某一个杯子中的水有d升?如果不能恰好做到d升,就让某一个杯子里 ...

  9. UVa 10603 Fill (BFS && 经典模拟倒水 && 隐式图)

    题意 : 有装满水的6升的杯子.空的3升杯子和1升杯子,3个杯子中都没有刻度.不使用道具情况下,是否可量出4升水呢? 你的任务是解决一般性的问题:设3个杯子的容量分别为a, b, c,最初只有第3个杯 ...

随机推荐

  1. Ubuntu系统下的多路径软件 DM Multipath 配置。

    Ubuntu系统下的多路径软件是操作系统自带的 DM Multipath工具.------------------------------------------------------------- ...

  2. window.location.href和window.top.location.href的区别

    if (window.location.href == window.top.location.href) {     window.top.location.href = "/index. ...

  3. webpack+react实现echarts可视化配置

    先上效果 开发环境要求 需要事先安装node及npm 前期准备 1.创建文件夹react-echarts-editor2.在项目根目录(以下称根目录)下创建src目录3.在项目根目录下创建dist目录 ...

  4. Java 位运算符 深入理解

    在Java中存在着这样一类操作符,是针对二进制进行操作的.它们各自是&.|.^.~.>>.<<.>>>几个位操作符.不管是初始值是依照何种进制,都会换 ...

  5. HBase 数据库检索性能优化策略

    HBase 数据表介绍 HBase 数据库是一个基于分布式的.面向列的.主要用于非结构化数据存储用途的开源数据库.其设计思路来源于 Google 的非开源数据库"BigTable" ...

  6. vim-缓存区中打开另外一个文件的方法

    现在有这么一种情况:    我现在在ubuntu用户根目录下--    我根目录下有一个文件夹blogs,这个文件夹下面有两个文件:text1,text2.    我现在从-目录下进行如下操作    ...

  7. ASPNET 页面编码

    转自:http://www.cnblogs.com/libingql/archive/2009/04/11/1433771.html 设置ASPNET页面编码格式 1.Web.Config设置 < ...

  8. SQl 行转列,列转行 (PIVOT,UPIVOT)

    1.列转行 表t_pivot 转后效果   方法 1 (常用方法 case when) SELECT     buydate, SUM(CASE WHEN type = '生活' THEN typec ...

  9. Android SecurityException

    public boolean checkNetwork() { boolean result = false; try { Context context = this.getApplicationC ...

  10. noi2019模拟测试赛(四十七)

    noi2019模拟测试赛(四十七) T1与运算(and) 题意: ​ 给你一个序列\(a_i\),定义\(f_i=a_1\&a_2\&\cdots\&a_i\),求这个序列的所 ...