【例题 7-8 UVA - 10603】Fill
【链接】 我是链接,点我呀:)
【题意】
在这里输入题意
【题解】
三维显然可以缩短为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的更多相关文章
- 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 ...
- 【路径寻找问题】UVa 10603 - Fill
如家大神书上的例题.第一次接触也是按代码敲得.敲的过程感觉很直观.但自己写估计会写的乱七八糟.以后不能砍得难就不愿意做这种题.否则只能做一些水题了.(PS:48) 紫书 #include<ios ...
- UVA 10603 Fill(正确代码尽管非常搓,网上很多代码都不能AC)
题目链接:option=com_onlinejudge&Itemid=8&page=show_problem&problem=1544">click here~ ...
- UVA 10603 - Fill BFS~
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&c ...
- UVA 10603 Fill
题意: 题目的意思是倒水,给出的四个数据是第一个水杯,第二个水杯,第三个水杯,和目标水量.一开始只有第三个水杯是满的,剩下的水杯是空的.倒水的时候只能把倒水出来的这个杯子倒空,或是倒水进去的杯子倒满. ...
- UVa 10603 Fill (暴力BFS+优先队列)
题意:给定4个数,a,b,c,d,分别代表空杯子容积为a,b,一个盛满水的杯子容积为c,让你不断倒水,找一个dd,是不是存在某个时刻, 某个杯子里的水dd,和d相同,或者无限接近.让求最少的倒水量和d ...
- UVA - 10603 Fill(隐式图搜索)
题目大意:经典的倒水问题. 给你三个瓶子,体积为a,b,c. 刚開始a.b是空的,c是满的,如今要求你到出体积为d的水.倒水的规则为,要么倒水方为空,要么接水方满 问倒到容量为d时,倒水的最小体积是多 ...
- UVA - 10603 Fill(BFS求最小值问题)
题目: 给出三个杯子(没有刻度线)的容量,起初之后第三个杯子是满的,其他的两个杯子是空的,容量分别是a.b.c.问最少需要倒多少升水才能让某一个杯子中的水有d升?如果不能恰好做到d升,就让某一个杯子里 ...
- UVa 10603 Fill (BFS && 经典模拟倒水 && 隐式图)
题意 : 有装满水的6升的杯子.空的3升杯子和1升杯子,3个杯子中都没有刻度.不使用道具情况下,是否可量出4升水呢? 你的任务是解决一般性的问题:设3个杯子的容量分别为a, b, c,最初只有第3个杯 ...
随机推荐
- openSUSE leap 42.3 添加HP Laserjet Pro M128fn打印机和驱动
一.安装驱动 YaST控制中心->软件管理->搜索->hplip 安装hplip 如下图: HPLIP(Linux Imaging and Printing Object)以前有hp ...
- Spring MVC学习总结(5)——SpringMVC项目关于安全的一些配置与实现方式
目前越来越多的应用和网站,开始注重安全性的问题,关于我们的web项目的几个安全知识点,不得不讲解一下,这里我主要讲述关于tomcat如何支持HTTPS连接访问,RSA公钥和私钥的制作.这个对于我们整个 ...
- CSUOJ 1532 JuQueen
Problem H JuQueen JuQueen is the super computer with the best performance allover Germany. It is on ...
- Android Netroid解析之——断点续传下载及问题修正
提到Netroid也许非常多人不知道这个框架,但我假设说Volley想必没有人不知道吧. Netroid是一个基于Volley实现的Android Http库.提供运行网络请求.缓存返回结果.批量图片 ...
- android中9-patch图片的使用
看了非常多文章的介绍,9.png图片有两种区域:可扩展区和内容显示区. 弄了半天才明确什么叫做可扩展区,什么叫做内容显示区. 分享一下自己的理解. 下图是某博客的截图: 图片来自:http://blo ...
- Icomparer和Icomparable集合排序
c#中实现对象集合的排序可以使用ArrayList中的Sort()方法,而有比较才能谈排序,因为不是基本类型(如string ,int.double......等)所以.NET Framework不可 ...
- solr简介
Solr 是什么? Solr它是一种开放源码的.基于 Lucene Java 的搜索服务器,易于加入到 Web 应用程序中. Solr 提供了层面搜索(就是统计).命中醒目显示并且支持多种输出格式(包 ...
- A股借壳上市?暂时没戏
近期股市波动,让不少P2P概念股打回原型.同花顺数据显示,上周五P2P概念股整体下跌9.28%,其中除了5家上市公司停牌外,14家P2P概念股跌幅都超过了9%.此前大热的多伦股份自6月23日以来,股价 ...
- 分享一个vue常用的ui控件
vue学习文档 http://www.jianshu.com/p/8a272fc4e8e8 vux github ui demo:https://github.com/airyland/vux M ...
- spark源码阅读
根据spark2.2的编译顺序来确定源码阅读顺序,只阅读核心的基本部分. 1.common目录 ①Tags②Sketch③Networking④Shuffle Streaming Service⑤Un ...