uva 10603
紫皮书的例题
照着敲了一遍,非原创
大题思路主要是三杯水,而水的总数是知道的,相当于知道第一第二杯水的体积,第三杯水的体积也就确定了。
用第一第二杯水的体积来标记数组是否遍历过
优先队列来找移动体积最少的
主要update_ans()函数进行每次判断
void update_ans(Node & u){
for(int i = ;i < ;i++){
int d = u.v[i];
if(ans[d] < || ans[d] > u.dist)
ans[d] = u.dist;
}
}
然后就是找第i杯水应该往第j杯水移动水的体积
符合条件进行入队操作
最后在ans数组寻找合适的解……!!!
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <stack>
#include <cctype>
#include <string>
#include <malloc.h>
#include <queue>
#include <map> using namespace std; const int INF = 0xffffff;
const double esp = 10e-;
const double Pi = * atan(1.0);
const int Maxn = +;
const int mod = ;
const int dr[] = {,,-,,-,,-,};
const int dc[] = {,,,-,,-,-,}; struct Node{
int v[];
int dist;
bool operator < (const Node & rhs)const{
return dist > rhs.dist;
}
}; int vis[Maxn][Maxn],cap[],ans[Maxn]; void update_ans(const Node & u){
for(int i = ;i < ;i++){
int d = u.v[i];
if(ans[d] < || u.dist < ans[d])
ans[d] = u.dist;
}
} void solve(int a,int b,int c,int d){
cap[] = a,cap[] = b,cap[] = c;
memset(vis,,sizeof(vis));
memset(ans,-,sizeof(ans));
priority_queue<Node>q; Node start;
start.dist = ;
start.v[] = ;
start.v[] = ;
start.v[] = c;
q.push(start); vis[][] = ;
while(!q.empty()){
Node u = q.top();
q.pop();
update_ans(u);
if(ans[d] >= )
break;
for(int i = ;i < ;i++){
for(int j = ;j < ;j++){
if(i == j){
continue;
}
if(u.v[i] == || u.v[j] == cap[j])
continue;
int amount = min(cap[j],u.v[i]+u.v[j]) - u.v[j];///计算将i倒入j的数量
Node u2;
memcpy(&u2,&u,sizeof(u));
u2.dist = u.dist + amount;
u2.v[i] -= amount;
u2.v[j] += amount;
if(!vis[u2.v[]][u2.v[]]){
vis[ u2.v[] ][u2.v[] ] = ;
q.push(u2);
}
}
}
}
while(d >= ){
if(ans[d] >= ){
printf("%d %d\n",ans[d],d);
return;
}
d--;
}
} int main()
{
#ifndef ONLINE_JUDGE
freopen("inpt.txt","r",stdin);
#endif
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);
}
return ;
}
uva 10603的更多相关文章
- 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 [暴力枚举、路径搜索]
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
题意: 题目的意思是倒水,给出的四个数据是第一个水杯,第二个水杯,第三个水杯,和目标水量.一开始只有第三个水杯是满的,剩下的水杯是空的.倒水的时候只能把倒水出来的这个杯子倒空,或是倒水进去的杯子倒满. ...
- 倒水问题(Fill,UVA 10603) lrj白书 p202
看着lrj的代码自己敲了一遍,还没调试成功.... 有时间再进行完善 /* 状态start到各个状态u1,u2,u3..... 的倒水量分别为u1.dist,u2.dist,u3.dist.... * ...
- 倒水问题(Fill, UVa 10603)
[题目描述] 有三个没有刻度的水壶,容量分别为a,b和c(单位为升,都是<=200的正整数).初始时前两个水壶是空的,而第三个装满了水.每次可以从一个水壶往一个水壶里倒水,直到一个水壶倒空或者另 ...
- UVa 10603 倒水问题
https://vjudge.net/problem/UVA-10603 题意:三个杯子,倒水问题.找出最少倒水量. 思路:路径寻找问题.不难,暴力枚举. #include<iostream&g ...
- UVa 10603 Fill (暴力BFS+优先队列)
题意:给定4个数,a,b,c,d,分别代表空杯子容积为a,b,一个盛满水的杯子容积为c,让你不断倒水,找一个dd,是不是存在某个时刻, 某个杯子里的水dd,和d相同,或者无限接近.让求最少的倒水量和d ...
随机推荐
- Verilog实现IIC通讯第二版
HMC5883三轴磁力传感器IIC通讯模块的VerilogHDL的实现 上一版并没有实现我想要的功能 0.0.1版 正在修订中 2013/9/2 //date :2013/7/7 //desi ...
- javaScript 网页特效 输出语句
大家好,我是小强老师,今天主要讲解 三个最为常用的输出语句. alert() 弹出警示框 window.alert(‘继续学习’); 完整的写法 效果如下: 因为alert 属于window 对象 ...
- android 根据域名得到IP
public static String GetInetAddress(String host) { String IPAddress = ""; InetAddress Retu ...
- 使用MongoDB的开源项目(转)
根据谷歌的搜索结果筛选出来的. 统计应用 counlty https://count.ly/ mongopress 开源CMS系统 http://www.mongopress.org/ Rubedo ...
- 以正确的方式开源 Python 项目
以正确的方式开源 Python 项目 大多数Python开发者至少都写过一个像工具.脚本.库或框架等对其他人也有用的工具.我写这篇文章的目的是让现有Python代码的开源过程尽可能清 晰和无痛.我不是 ...
- wget -r -nc -np "http://www.zhihu.com/"
下载网站所有 -r, --recursive specify recursive download. -nc, --no-clobber skip dow ...
- 将一个int转成二进制c
/* 由于是2位 十进制整数,所以转化后可以存 一个int 型中: reverse函数 提供了这种转化 如果需要转化的数字比较大int存不下,则需要数组来存 */ #include<stdio. ...
- javascript每日一练(十二)——运动框架
运动框架 可以实现多物体任意值运动 例子: <!doctype html> <html> <head> <meta charset="utf-8&q ...
- while和do while习题
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace 练习 { ...
- 类作为返回类型 ,具有java特点-封装等 而且应用起来很方便。
public class StudentDao { public Student getStudent(){ Student stu = new Student(); stu.setName(&quo ...