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. 普通Java类获取Spring的Bean的方法

    普通Java类获取Spring的Bean的方法 在SSH集成的前提下.某些情况我们需要在Action以外的类中来获得Spring所管理的Service对象. 之前我在网上找了好几好久都没有找到合适的方 ...

  2. POJ 1269 Intersecting Lines(直线求交点)

    Description We all know that a pair of distinct points on a plane defines a line and that a pair of ...

  3. c#和.net区别

    .net 包含两大部分:.net framework类库和公共语言运行库(CLR) .net framework类库,就是微软工程师写好的各种功能类,例如math类. 公共语言运行库:1.与操作系统进 ...

  4. Java中I/O流之轮换流

    Java 中的轮换流: 非常有用,可以把一个字节流转换成字符流. inputStreamReader, outputStreamReader Demo_1: import java.io.*; cla ...

  5. Swift中避免在多个文件中重复import相同的第三方包

    swift中由于有命名空间的存在,在同一个target创建的文件,都可以不引用直接就可以拿来使用,但是不同target之间必须要import 之后才能使用,在不同的文件中使用都要重复的import这个 ...

  6. week12 201621044079 流与文件

    作业12-流与文件 1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多流与文件相关内容. 2. 面向系统综合设计-图书馆管理系统或购物车 使用流与文件改造你的图书馆管理系统或购物车 ...

  7. 【week4】课堂Scrum站立会议

    项目:连连看游戏 小组名称:天天向上(旁听) 小组成员:张政 张金生 李权 武致远 已完成任务 1.本项目采用c#. 2. 初步界面. 形成一个windows下的游戏界面,每个需要消除的方块是一个bu ...

  8. phpcms 本地环境调试缓慢 解决办法

    用记事本打开host文件,(文件位置,windows下一般在路径C:\Windows\System32\drivers\etc下)找到#127.0.0.1      localhost 这一句  去掉 ...

  9. C# 使用this的形参

    示例1: public static RectangleF TransformRect(this Matrix mat, RectangleF rect) 是向Matrix类扩展带有Rectangle ...

  10. c#中语句的先后顺序对结果的影响

    using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Test ...