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. mac上golang编译出现clang错误

    错误现象 几周前,突然发现我的go 项目编译开始报一种以前从来没有出现过的错误: # runtime/cgo clang: warning: argument unused during compil ...

  2. [leetcode-744-Find Smallest Letter Greater Than Target]

    Given a list of sorted characters letters containing only lowercase letters, and given a target lett ...

  3. [leetcode-676-Implement Magic Dictionary]

    Implement a magic directory with buildDict, and search methods. For the method buildDict, you'll be ...

  4. Bad Cowtractors(最大生成树)

      Description Bessie has been hired to build a cheap internet network among Farmer John's N (2 <= ...

  5. P4编程环境搭建遇到的问题与解决方法

    在经历了无数的折腾之后,算是折腾,最后采用的是陈翔学长的脚本加上可爱的shell调整装好的. 链接:p4Install 也许是ubuntu18.04的问题,也有可能是我自己把这个系统折腾的有点杂乱的原 ...

  6. Unity3d学习日记(三)

      使用Application.LoadLevel(Application.loadedLevel);来重新加载游戏scene的方法已经过时了,我们可以使用SceneManager.LoadScene ...

  7. SQL SERVER技术内幕之4 子查询

    最外层查询的结果集会返回给调用者,称为外部查询.内部查询的结果是供外部查询使用的,也称为子查询.子查询可以分成独立子查询和相关子查询两类.独立子查询不依赖于它所属的外部查询,而相关子查询则须依赖它所属 ...

  8. ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction 表被锁的解决办法

    转自:https://blog.csdn.net/mchdba/article/details/38313881 前言:朋友咨询我说执行简单的update语句失效,症状如下:mysql> upd ...

  9. C语言100例02 PHP版(练习)

    问题: 企业发放的奖金根据利润提成. 利润(I)低于或等于10万元时,奖金可提10%: 利润高于10万元,低于20万元时,低于10万元的部分按10%提成,高于10万元的部分,可提成7.5%: 20万到 ...

  10. JQuery UI的拖拽功能实现方法小结

    JQuery UI提供的API极大简化了拖拽功能的开发.只需要分别在拖拽源(source)和目标(target)上调用draggable和droppable两个函数即可. 拖拽原理 首先要明确几个概念 ...