https://vjudge.net/problem/UVA-10603

题意:

倒水问题,输出最少的倒水量和目标水量

如果无解,目标水量就是尽可能接近给定点的目标水量,但不得大于给定的目标水量

推推公式,不用分类讨论~\(≧▽≦)/~啦啦啦

#include<cstdio>
#include<cstring>
#include<queue>
#define N 201
using namespace std;
struct node
{
int v[],dis;
bool operator < (node p) const
{
return dis>p.dis;
}
}now,nxt;
int v[N][N],cap[],ans[N];
void up()
{
int d;
for(int i=;i<;i++)
{
d=now.v[i];
if(ans[d]< || now.dis<ans[d]) ans[d]=now.dis;
}
}
void solve(int a,int b,int c,int d)
{
cap[]=a; cap[]=b; cap[]=c;
memset(v,,sizeof(v));
memset(ans,-,sizeof(ans));
priority_queue<node>q;
node s;
s.dis=; s.v[]=; s.v[]=; s.v[]=c;
q.push(s);
v[][]=;
while(!q.empty())
{
now=q.top(); q.pop();
up();
if(ans[d]>=) break;
for(int i=;i<;i++)
for(int j=;j<;j++)
if(i!=j)
{
if(!now.v[i] || now.v[j]==cap[j]) continue;//
int amount=min(cap[j],now.v[i]+now.v[j])-now.v[j];
nxt=now;
nxt.dis+=amount;
nxt.v[i]-=amount;
nxt.v[j]+=amount;
if(!v[nxt.v[]][nxt.v[]]) { v[nxt.v[]][nxt.v[]]=true; q.push(nxt); }
}
}
while(d>=)
{
if(ans[d]>=) { printf("%d %d\n",ans[d],d); return;}
d--;
}
}
int main()
{
int T,a,b,c,d;
scanf("%d",&T);
while(T--)
{
scanf("%d%d%d%d",&a,&b,&c,&d);
solve(a,b,c,d);
}
}

uva 10683 Fill的更多相关文章

  1. uva 11520 - Fill the Square

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

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

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

  3. Uva 11520 - Fill the Square 贪心 难度: 0

    题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...

  4. UVA 10603 - Fill BFS~

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

  5. 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 ...

  6. UVa 11520 Fill the Square 填充正方形

    在一个 n * n 网格中填了一些大写字母,你的任务是把剩下的格子中也填满大写字母,使得任意两个相邻格子(即有公共边的格子)中的字母不同.如果有多重填法,则要求按照从上到下,从左到右的顺序把所有格子连 ...

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

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

  8. UVA 10603 Fill

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

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

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

随机推荐

  1. Hadoop源码解析 1 --- Hadoop工程包架构解析

    1 Hadoop中各工程包依赖简述     Google的核心竞争技术是它的计算平台.Google的大牛们用了下面5篇文章,介绍了它们的计算设施.     GoogleCluster: http:// ...

  2. [ML] the notes

    "Machine Learning is not who has the best algorithm that wins. It is who has the most data.&quo ...

  3. Python—元组(戴上了枷锁的列表)

    一.概念 元组属于不可变序列,元组是包含多个元素的类型,元素之间用逗号分割.例如:t1=123,456,“hello”元组可以是空的,t2=()元组包含一个元素时:t3=123,元组外侧可以使用括号, ...

  4. 初学c#(又要打代码了好难)

    因为我原来从没有学过C#,所以要重新看一个语言的基本语法,仔细阅读了老师的作业要求,发现第一个10分的作业如果要用c语言写我是可以完成的,于是定个小目标就是在周日前完成作业的第一步.今天我在菜鸟教程的 ...

  5. zookeeper启动配置

    zookeeper安装和配置详解 转载 2014年04月16日 14:36:31 16812 摘自:http://www.ibm.com/developerworks/cn/opensource/os ...

  6. Java常用类之String

    String 类: 1. java.lang.String 类代表不可变的字符序列:  2. “XXX” 为该类的一个对象: 3. String 类的常用构造方法: ① String(String o ...

  7. python学习笔记06:操作文件

    调用内置的open函数打开文件,传递两个参数:文件路径(绝对路径或相对路径),打开模式('r':读,'r+':读写,'w':写,'b':二进制): f = open('data.txt','w') f ...

  8. Uncaught ReferenceError: wx is not defined

    程序的分享功能调用了微信的接口,但是忽然发现就报这个错误, Uncaught ReferenceError: wx is not defined 同时下方还有这个错误 This content sho ...

  9. 修改IntelliJ IDEA字体

  10. 统一日志系统 Log4Net/ExceptionLess

    一.   写在前面 本文Log4Net介绍了基础的方式,大数据量生产环境不能使用,中等日志量请日志单库. 希望爱技术的你不要错过exceptionless和ELK 第四节开始简单配置大牛们推荐的了Ex ...